(not (empty? coll)). Instead prefer
(seq coll) instead.
Seq returns nil if the collection is empty. If the seq isn't empty then it returns a seq on that collection.
If the result of a
map function ever returns a list of lists, then use
(apply (concat (map...))):
Maps, like keywords, are functions.
You can access a map using a keyword as the function, the map as the function, or
get as the function:
If you don't need to return a default value, in which you would use the
get function, it's preferable to use a keyword as the function instead of the map (the middle version).
This protects you from possible null pointer exceptions. Keywords can never be nil, while you can have a nil bound to what your map is.
Using a keyword to access
nil returns nil. However, using
nil to access a keyword is a null pointer exception.
Similarly to maps, sets, while not used nearly as often as maps, are also functions.
You can define sets using the
set function or
It returns the value if is present within the set and nil if it isn't.
This property allows us do a few interesting things.
contains?on a set
If you have a set, you don't need to use the
contains? function to see if a key is present. Just use the set as the function.
(every? key-set (keys my-map))Idiom
This is useful in testing JSON responses for example. You can assert that the keys of the response map returned is within the set of keys you expected to return.
If you find yourself using threading macros like
->> on a map and need to conditionally assoc/dissoc, use