Liking cljdoc? Tell your friends :D

funjible.set

Set operations such as union/intersection.

Set operations such as union/intersection.
raw docstring

differenceclj

(difference s1)
(difference s1 s2)
(difference s1 s2 & sets)

Return a set that is the first set without elements of the remaining sets. Throws exception if any argument is not a set. The returned set will have the same metadata as s1, and will have the same 'sortedness', i.e. the returned set will be sorted if and only if s1 is.

Example: user=> (difference #{2 4 6 8 10 12} #{3 6 9 12}) #{2 4 8 10}

Return a set that is the first set without elements of the
remaining sets.  Throws exception if any argument is not a set.  The
returned set will have the same metadata as s1, and will have the
same 'sortedness', i.e. the returned set will be sorted if and only
if s1 is.

Example:
user=> (difference #{2 4 6 8 10 12} #{3 6 9 12})
#{2 4 8 10}
sourceraw docstring

indexclj

(index xrel ks)

Given a relation (a set of maps) xrel, return a map. The keys are themselves maps of the distinct values of ks in xrel. Each is mapped to the subset of xrel that has the corresponding values of ks. Throws exception if xrel is not a set. Each subset of xrel returned has the same metadata and 'sortedness' as xrel, i.e. they will be unsorted or sorted in the same way that xrel is.

user=> (def people #{{:name "Lakshmi", :age 8} {:name "Hans", :age 9} {:name "Rahul", :age 10} {:name "George", :age 8} {:name "Paula", :age 10}}) #'user/people user=> (index people [:age]) {{:age 8} #{{:age 8, :name "Lakshmi"} {:age 8, :name "George"}}, {:age 10} #{{:age 10, :name "Rahul"} {:age 10, :name "Paula"}}, {:age 9} #{{:age 9, :name "Hans"}}}

Given a relation (a set of maps) xrel, return a map.  The keys are
themselves maps of the distinct values of ks in xrel.  Each is
mapped to the subset of xrel that has the corresponding values of
ks.  Throws exception if xrel is not a set.  Each subset of xrel
returned has the same metadata and 'sortedness' as xrel, i.e. they
will be unsorted or sorted in the same way that xrel is.

user=> (def people #{{:name "Lakshmi", :age 8}
                     {:name "Hans", :age 9}
                     {:name "Rahul", :age 10}
                     {:name "George", :age 8}
                     {:name "Paula", :age 10}})
#'user/people
user=> (index people [:age])
{{:age 8} #{{:age 8, :name "Lakshmi"}
            {:age 8, :name "George"}},
 {:age 10} #{{:age 10, :name "Rahul"}
             {:age 10, :name "Paula"}},
 {:age 9} #{{:age 9, :name "Hans"}}}
sourceraw docstring

intersectionclj

(intersection s1)
(intersection s1 s2)
(intersection s1 s2 & sets)

Return a set that is the intersection of the input sets. Throws exception if any argument is not a set. The metadata and sortedness of the returned set is not promised, e.g. if you take the intersection of an unsorted and a sorted set, the returned set could be sorted or unsorted, and the metadata could be from either set.

Example: user=> (intersection #{:k1 #{8/3 5} "bar"} #{:k1 "goo" #{8/3 5}}) #{#{5 8/3} :k1}

Return a set that is the intersection of the input sets.  Throws
exception if any argument is not a set.  The metadata and sortedness
of the returned set is not promised, e.g. if you take the
intersection of an unsorted and a sorted set, the returned set could
be sorted or unsorted, and the metadata could be from either set.

Example:
user=> (intersection #{:k1 #{8/3 5} "bar"} #{:k1 "goo" #{8/3 5}})
#{#{5 8/3} :k1}
sourceraw docstring

joinclj

(join xrel yrel)
(join xrel yrel km)

When passed 2 relations (sets of maps), returns the relation corresponding to the natural join. When passed an additional keymap, joins on the corresponding keys. Throws exception if xrel or yrel are not sets, or if km is not a map. The returned set has no metadata, and is not guaranteed to be any particular type of set (e.g. if xrel is a sorted map, there is no promise the returned set will be sorted.)

When passed 2 relations (sets of maps), returns the relation
corresponding to the natural join.  When passed an additional
keymap, joins on the corresponding keys.  Throws exception if xrel
or yrel are not sets, or if km is not a map.  The returned set has
no metadata, and is not guaranteed to be any particular type of
set (e.g. if xrel is a sorted map, there is no promise the returned
set will be sorted.)
sourceraw docstring

map-invertclj

(map-invert m)

Returns the map with the vals mapped to the keys. If a val appears more than once in the map, only one of its keys will appear in the result. Do not rely on which one. Throws exception if m is not a map. The returned map has no metadata, and is not guaranteed to be any particular type of map (e.g. if m is a sorted map, there is no promise the returned map will be sorted).

Examples: user=> (map-invert {:a 1, :b 2}) {2 :b, 1 :a} user=> (map-invert {:a 1, :b 1}) {1 :b}

Returns the map with the vals mapped to the keys.  If a val appears
more than once in the map, only one of its keys will appear in the
result.  Do not rely on which one.  Throws exception if m is not a
map.  The returned map has no metadata, and is not guaranteed to be
any particular type of map (e.g. if m is a sorted map, there is no
promise the returned map will be sorted).

Examples:
user=> (map-invert {:a 1, :b 2})
{2 :b, 1 :a}
user=> (map-invert {:a 1, :b 1})
{1 :b}
sourceraw docstring

projectclj

(project xrel ks)

Takes a relation (a set of maps) xrel, and returns a relation where every map contains only the keys in ks. Throws exception if xrel is not a set. The metadata of the returned set will be the same as xrel.

Example: user=> (def rel #{{:name "Art of the Fugue" :composer "J. S. Bach"} {:name "Musical Offering" :composer "J. S. Bach"} {:name "Requiem" :composer "W. A. Mozart"}}) #'user/rel user=> (project rel [:composer]) #{{:composer "W. A. Mozart"} {:composer "J. S. Bach"}}

Takes a relation (a set of maps) xrel, and returns a relation where
every map contains only the keys in ks.  Throws exception if xrel is
not a set.  The metadata of the returned set will be the same as
xrel.

Example:
user=> (def rel #{{:name "Art of the Fugue" :composer "J. S. Bach"}
                  {:name "Musical Offering" :composer "J. S. Bach"}
                  {:name "Requiem" :composer "W. A. Mozart"}})
#'user/rel
user=> (project rel [:composer])
#{{:composer "W. A. Mozart"}
  {:composer "J. S. Bach"}}
sourceraw docstring

renameclj

(rename xrel kmap)

Takes a relation (a set of maps) xrel, and returns a relation where all keys of xrel that are in kmap have been renamed to the corresponding vals in kmap. Throws exception if xrel is not a set or kmap is not a map. The metadata of the returned set will be the same as xrel.

Example: user=> (def rel #{{:name "Art of the Fugue" :composer "J. S. Bach"} {:name "Musical Offering" :composer "J. S. Bach"} {:name "Requiem" :composer "W. A. Mozart"}}) #'user/rel user=> (rename rel {:name :title}) #{{:title "Art of the Fugue", :composer "J. S. Bach"} {:title "Musical Offering", :composer "J. S. Bach"} {:title "Requiem", :composer "W. A. Mozart"}}

Takes a relation (a set of maps) xrel, and returns a relation where
all keys of xrel that are in kmap have been renamed to the
corresponding vals in kmap.  Throws exception if xrel is not a set
or kmap is not a map.  The metadata of the returned set will be the
same as xrel.

Example:
user=> (def rel #{{:name "Art of the Fugue" :composer "J. S. Bach"}
                  {:name "Musical Offering" :composer "J. S. Bach"}
                  {:name "Requiem" :composer "W. A. Mozart"}})
#'user/rel
user=> (rename rel {:name :title})
#{{:title "Art of the Fugue", :composer "J. S. Bach"}
  {:title "Musical Offering", :composer "J. S. Bach"}
  {:title "Requiem", :composer "W. A. Mozart"}}
sourceraw docstring

rename-keysclj

(rename-keys map kmap)

Returns the map with the keys in kmap renamed to the vals in kmap. Throws exception if any argument is not a map. The metadata and 'sortedness' of the returned map will be the same as map, i.e. it will be unsorted or sorted in the same way that map is.

Examples: user=> (rename-keys {:a 1 :b 2 :c 3} {:a :apple :b :bop}) {:bop 2, :apple 1, :c 3}

;; It handles cases like this correctly, too. user=> (rename-keys {:a 1, :b 2, :c 3} {:a :b, :b :a}) {:a 2, :b 1, :c 3}

Returns the map with the keys in kmap renamed to the vals in kmap.
Throws exception if any argument is not a map.  The metadata and
'sortedness' of the returned map will be the same as map, i.e. it
will be unsorted or sorted in the same way that map is.

Examples:
user=> (rename-keys {:a 1 :b 2 :c 3} {:a :apple :b :bop})
{:bop 2, :apple 1, :c 3}

;; It handles cases like this correctly, too.
user=> (rename-keys {:a 1, :b 2, :c 3} {:a :b, :b :a})
{:a 2, :b 1, :c 3}
sourceraw docstring

selectclj

(select pred xset)

Returns a set of the elements for which pred is true. Throws exception if xset is not a set. The metadata and 'sortedness' of the returned set will be the same as xset, i.e. it will be unsorted or sorted in the same way that xset is.

Example: user=> (select even? #{3 6 9 12 15 18}) #{6 12 18}

Returns a set of the elements for which pred is true.  Throws
exception if xset is not a set.  The metadata and 'sortedness' of
the returned set will be the same as xset, i.e. it will be unsorted
or sorted in the same way that xset is.

Example:
user=> (select even? #{3 6 9 12 15 18})
#{6 12 18}
sourceraw docstring

subset?clj

(subset? set1 set2)

Is set1 a subset of set2? True if the sets are equal. Throws exception if any argument is not a set.

Examples: user=> (subset? #{"two" "strings"} #{"strings" "two" "plus"}) true user=> (subset? #{3 4 5} #{3 4 7}) false

Is set1 a subset of set2?  True if the sets are equal.  Throws
exception if any argument is not a set.

Examples:
user=> (subset? #{"two" "strings"} #{"strings" "two" "plus"})
true
user=> (subset? #{3 4 5} #{3 4 7})
false
sourceraw docstring

superset?clj

(superset? set1 set2)

Is set1 a superset of set2? True if the sets are equal. Throws exception if any argument is not a set.

Examples: user=> (superset? #{"this" "has" "more"} #{"this" "has"}) true user=> (superset? #{2 3 5 7 11 13} #{9}) false

Is set1 a superset of set2?  True if the sets are equal.  Throws
exception if any argument is not a set.

Examples:
user=> (superset? #{"this" "has" "more"} #{"this" "has"})
true
user=> (superset? #{2 3 5 7 11 13} #{9})
false
sourceraw docstring

unionclj

(union)
(union s1)
(union s1 s2)
(union s1 s2 & sets)

Return a set that is the union of the input sets. Throws exception if any argument is not a set. The metadata and sortedness of the returned set is not promised, e.g. if you take the union of an unsorted and a sorted set, the returned set could be sorted or unsorted, and the metadata could be from either set.

Example: user=> (union #{1 :a "b"} #{:a "b" -82 {:foo 7}}) #{1 :a "b" {:foo 7} -82}

Return a set that is the union of the input sets.  Throws exception
if any argument is not a set.  The metadata and sortedness of the
returned set is not promised, e.g. if you take the union of an
unsorted and a sorted set, the returned set could be sorted or
unsorted, and the metadata could be from either set.

Example:
user=> (union #{1 :a "b"} #{:a "b" -82 {:foo 7}})
#{1 :a "b" {:foo 7} -82}
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close