Universal and complement sets, set operations.

Universal sets are useful as identity elements for reductions and folding, for example:

(reduce intersection [#{0 1 2} #{1 2 3} #{2 3 4}])
;;=> #{2}
Prefer aliasing this namespace (as shown in the usage example) to refering its functions.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(ns foo.bar
  (:api dunaj)
  (:require [dunaj.set :as ds]))

(ds/set-complement #{})
;;=> 𝕌

(ds/difference ds/U #{1 2})
;;=> #{1 2}ᶜ

(ds/union #{1} (disj ds/U 3) (disj ds/U 4 3) #{4})
;;=> #{3}ᶜ

(ds/union (disj ds/U 3 4) (disj ds/U 4) #{4})
;;=> 𝕌

(ds/intersection (disj ds/U 3) (disj ds/U 4 3))
;;=> #{4 3}ᶜ

(ds/intersection #{4 5} (disj ds/U 3 5) #{3 4})
;;=> #{4}

Primary

ComplementSet

Available since version 1.0 (view source)

not referred automatically

TYPE

A type for absolute complement set.

U

Available since version 1.0 (view source)

not referred automatically

VAR of type UniversalSet

Universal set 𝕌.

See also: set-complement, finite?

UniversalSet

Available since version 1.0 (view source)

not referred automatically

TYPE

A type for universal set.

complement?

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (complement? x)

Type signature: Predicate

Returns true if object x is an instance of ComplementSet type, false otherwise.

finite?

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (finite? set)

Type signature:
  • (#{}) → Boolean+

Returns true is set is finite, false otherwise.

See also: set-complement, U

universal?

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (universal? x)

Type signature: Predicate

Returns true if object x is an instance of UniversalSet type, false otherwise.

Operations

difference

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (difference s1)

  • (difference s1 s2)

  • (difference s1 s2 & sets)

Type signatures:
  • (#{}) → #{}

  • (#{} ⨯ #{}) → #{}

  • (#{} ⨯ #{} ⨯ (Va #{})) → #{}

Returns a set that is the first set without items of the remaining sets.

See also: union, intersection

index

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (index xrel ks)

Type signature:
  • (#{} ⨯ [Any]) → {}

Returns a map of the distinct values of ks in the xrel mapped to a set of the maps in xrel with the corresponding values of ks.

intersection

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (intersection)

  • (intersection s1)

  • (intersection s1 s2)

  • (intersection s1 s2 & sets)

Type signatures:
  • () → #{}

  • (#{}) → #{}

  • (#{} ⨯ #{}) → #{}

  • (#{} ⨯ #{} ⨯ (Va #{})) → #{}

Return a set that is the intersection of the input sets. (intersection) returns 𝕌.

See also: union, difference

join

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (join xrel yrel)

  • (join xrel yrel km)

Type signatures:
  • (#{} ⨯ #{}) → #{}

  • (#{} ⨯ #{} ⨯ {}) → #{}

When passed 2 rels, returns the rel corresponding to the natural join. When passed an additional keymap km, joins on the corresponding keys.

project

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (project xrel ks)

Type signature:
  • (#{} ⨯ [Any]) → #{}

Returns a rel of the items of xrel with only the keys in ks.

See also: select, rename

rename

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (rename xrel kmap)

Type signature:
  • (#{} ⨯ {}) → #{}

Returns a rel of the maps in xrel with the keys in kmap` renamed to the vals in `kmap.

select

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (select pred xset)

Type signature:
  • (Predicate ⨯ #{}) → #{}

Returns a set of the items from xset for which pred is logically true.

See also: project

set-complement

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (set-complement set)

Type signature:
  • (#{}) → #{}

Returns setᶜ, a complement of set.

See also: U, finite?

subset?

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (subset? s1 s2)

Type signature:
  • (#{} ⨯ #{}) → Boolean+

Returns true if s1 is a subset of s2, otherwise returns false.

superset?

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (superset? s1 s2)

Type signature:
  • (#{} ⨯ #{}) → Boolean+

Returns true if s1 is a superset of s2, otherwise returns false.

union

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (union)

  • (union s1)

  • (union s1 s2)

  • (union s1 s2 & sets)

Type signatures:
  • () → #{}

  • (#{}) → #{}

  • (#{} ⨯ #{}) → #{}

  • (#{} ⨯ #{} ⨯ (Va #{})) → #{}

Return a set that is the union of the input sets. (union) returns #{}.