Liking cljdoc? Tell your friends :D
All platforms.

where.core

Provides a function called where which facilitate the building of complex predicates for filter, especially useful with maps.

Provides a function called `where` which facilitate
the building of complex predicates for `filter`,
especially useful with maps.
raw docstring

whereclj/s

(where [op & rules :as cond-spec])
(where comparator value)
(where extractor comparator value)

It builds a predicate function in a more human readable way.

It takes an extractor which applied to the item it will return the property you want to compare. Then second argument is the comparator which it can be any binary comparator function, and it take a value to compare to.

For example if you have a collection users which contains map with the following format:

[{:name "Kiayada Wyatt", :user "kiayada33", :age 33, :country "USA", :active true } ,,,]

and let' say you want to find all users coming from "USA"

(filter (where :country = "USA") users)

to get the users which are over 18yo you can write.

(filter (where :age > 18) users)

where can be used not only with maps but also with lists, vectors, sets.

(filter (where > 6) (range 20))

Additionally you can easily compose condition with logical operators such as :and, :or and :not

(filter (where [:and [:country = "USA"] [:age > 18]]) users)

Finally there are number of built-in operators which provide a easy, nil-safe, and expressive way to define common where clauses. These operators are:

(*) Strings

| comparator | complement (not) | case-insensitive | insensitive complement | |---------------+-------------------+------------------+------------------------| | :is? | :is-not? | :IS? | :IS-NOT? | | :starts-with? | :not-starts-with? | :STARTS-WITH? | :NOT-STARTS-WITH? | | :ends-with? | :not-ends-with? | :ENDS-WITH? | :NOT-ENDS-WITH? | | :contains? | :not-contains? | :CONTAINS? | :NOT-CONTAINS? | | :in? | :not-in? | :IN? | :NOT-IN? | | :matches? | :not-matches? | :MATCHES? | :NOT-MATCHES? |

(*) Numbers

| comparator | complement (not) | |--------------------+------------------------| | :between? | :not-between? | | :strictly-between? | :not-strictly-between? | | :range? | :not-range? | | :in? | :not-in? |

For more info please visit: https://github.com/BrunoBonacci/where

It builds a predicate function in a more human readable way.

It takes an `extractor` which applied to the item it will return the
property you want to compare. Then second argument is the comparator
which it can be any binary `comparator` function, and it take a
`value` to compare to.

For example if you have a collection `users` which contains map with
the following format:

   [{:name "Kiayada Wyatt", :user "kiayada33", :age 33,
     :country "USA", :active true } ,,,]

and let' say you want to find all users coming from "USA"

   (filter (where :country = "USA") users)

to get the users which are over 18yo you can write.

   (filter (where :age > 18) users)

`where` can be used not only with maps but also with lists, vectors,
sets.

   (filter (where > 6) (range 20))

Additionally you can easily compose condition with logical operators such
as `:and`, `:or` and `:not`

   (filter (where [:and [:country = "USA"] [:age > 18]]) users)


Finally there are number of built-in operators which provide a easy,
nil-safe, and expressive way to define common `where` clauses.
These operators are:

(*) Strings

| comparator    | complement (not)  | case-insensitive | insensitive complement |
|---------------+-------------------+------------------+------------------------|
| :is?          | :is-not?          | :IS?             | :IS-NOT?               |
| :starts-with? | :not-starts-with? | :STARTS-WITH?    | :NOT-STARTS-WITH?      |
| :ends-with?   | :not-ends-with?   | :ENDS-WITH?      | :NOT-ENDS-WITH?        |
| :contains?    | :not-contains?    | :CONTAINS?       | :NOT-CONTAINS?         |
| :in?          | :not-in?          | :IN?             | :NOT-IN?               |
| :matches?     | :not-matches?     | :MATCHES?        | :NOT-MATCHES?          |

(*) Numbers

| comparator         | complement (not)       |
|--------------------+------------------------|
| :between?          | :not-between?          |
| :strictly-between? | :not-strictly-between? |
| :range?            | :not-range?            |
| :in?               | :not-in?               |


For more info please visit: https://github.com/BrunoBonacci/where
sourceraw docstring

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

× close