• Effekt Logo Effekt Library
    • set
      • Set
      • empty
      • emptyGeneric
      • isEmpty
      • nonEmpty
      • singleton
      • singletonGeneric
      • size
      • insert
      • fromMapKeys
      • toMap
      • fromList
      • fromListGeneric
      • foreach
      • toList
      • all
      • any
      • contains
      • subset
      • superset
      • delete
      • deleteMany
      • difference
      • difference
      • union
      • union
      • intersection
      • intersection
    • set
    • Jump to source: libraries/common/set.effekt
      Example usage: examples/stdlib/set
      • Set [A] (tree: Tree[A, Unit], compare: (A, A) => Ordering at {})
      • Ordered finite immutable set, backed by balanced binary trees of logarithmic depth.
      • empty [A] (compare: (A, A) => Ordering at {}): Set[A] / {}
      • Create a new empty set using a pure, first-class comparison function.
        
        O(1)
      • emptyGeneric [A]: Set[A] / {}
      • Create a new empty set using a generic comparison function.
        Only available on JavaScript backends!
        
        O(1)
      • isEmpty [A] (s: Set[A]): Bool / {}
      • Check if set `s` is empty.
        
        O(1)
      • nonEmpty [A] (s: Set[A]): Bool / {}
      • Check if set `s` is nonempty.
        
        O(1)
      • singleton [A] (element: A, compare: (A, A) => Ordering at {}): Set[A] / {}
      • Create a new set containing a single `element`.
        Requires a pure, first-class comparison function.
        
        O(1)
      • singletonGeneric [A] (element: A): Set[A] / {}
      • Create a new set containing a single `element` and a generic comparison function.
        Only available on the JavaScript backends!
        
        O(1)
      • size [A] (s: Set[A]): Int / {}
      • Get the size of the set (the number of its elements).
        
        O(1)
      • insert [A] (s: Set[A], a: A): Set[A] / {}
      • Insert a new element `a` into the set `s`.
        
        O(log N)
      • fromMapKeys [K, V] (map: Map[K, V]): Set[K] / {}
      • Create a set from a given map by ignoring the values.
        
        O(N)
      • toMap [K, V] (keys: Set[K]) { valueOf: (K) => V }: Map[K, V] / {}
      • Create a map from a set and a function,
        reusing the set's comparison.
        
        O(N)
      • fromList [A] (list: List[A], compare: (A, A) => Ordering at {}): Set[A] / {}
      • Create a set from a given list and a pure, first-class comparison function.
        
        O(N log N)
        O(N) if the list is sorted
      • fromListGeneric [A] (list: List[A]): Set[A] / {}
      • Create a set from a given list with a generic comparison function.
        Works only on the JavaScript backends!
        
        O(N log N)
        O(N) if the list is sorted
      • foreach [A] (s: Set[A]) { action: (A) => Unit }: Unit / {}
      • Traverse all elements in order, running the function `action` on each element.
        
        Law: `s.foreach { action } === s.toList.foreach { action }`
        
        O(N)
      • toList [A] (s: Set[A]): List[A] / {}
      • Create a list from a given set.
        
        O(N)
      • all [A] (s: Set[A]) { predicate: (A) => Bool }: Bool / {}
      • Check if a predicate holds for all elements in a given set.
        
        O(N)
      • any [A] (s: Set[A]) { predicate: (A) => Bool }: Bool / {}
      • Check if a predicate holds for at least one element in a given set.
        
        O(N)
      • contains [A] (s: Set[A], a: A): Bool / {}
      • Check if a set contains a given element.
        
        O(log N)
      • subset [A] (s1: Set[A], s2: Set[A]): Bool / {}
      • Check if set `s1` is a subset of set `s2`.
        
        O(N log N)
      • superset [A] (s1: Set[A], s2: Set[A]): Bool / {}
      • Check if set `s1` is a superset of set `s2`.
        
        O(N log N)
      • delete [A] (s: Set[A], a: A): Set[A] / {}
      • Remove an element from a set.
        If the element is not in the set, the original set is returned.
        
        O(log N)
      • deleteMany [A] (s: Set[A], list: List[A]): Set[A] / {}
      • Remove many elements from a set.
        
        O(M log N) where M is the size of the list.
      • difference [A] (s1: Set[A], s2: Set[A], compare: (A, A) => Ordering at {}): Set[A] / {}
      • Construct a new set which contains all elements of `s1`
        except those where the element is in `s2`.
        Uses an explicit comparison function.
        
        O(???)
      • difference [A] (s1: Set[A], s2: Set[A]): Set[A] / {}
      • Construct a new set which contains all elements of `s1`
        except those where the element is in `s2`.
        Uses a comparison function from `s1`.
        
        O(???)
      • union [A] (s1: Set[A], s2: Set[A], compare: (A, A) => Ordering at {}): Set[A] / {}
      • Construct a new set which contains both elements of `s1` and `s2`.
        Uses an explicit comparison function.
        
        O(???)
      • union [A] (s1: Set[A], s2: Set[A]): Set[A] / {}
      • Construct a new set which contains both elements of `s1` and `s2`.
        Uses a comparison function from `s1`.
        
        O(???)
      • intersection [A] (s1: Set[A], s2: Set[A], compare: (A, A) => Ordering at {}): Set[A] / {}
      • Construct a new set which contains only elements which are in both of `s1` and `s2`.
        Uses an explicit comparison function.
        
        O(???)
      • intersection [A] (s1: Set[A], s2: Set[A]): Set[A] / {}
      • Construct a new set which contains only elements which are in both of `s1` and `s2`.
        Uses a comparison function from `s1`.
        
        O(???)