Liking cljdoc? Tell your friends :D

one-see.core

A lightweight utility for establishing and querying symmetric one-to-one relationships.

A lightweight utility for establishing and querying symmetric one-to-one
relationships.
raw docstring

look-upclj

(look-up s)
(look-up s ->rec)

Returns a LookUp instance which provides efficient look ups of symmetric one-to-one relationships.

The 1-arity invocation accepts a sequential s of hash-maps. The 2-arity invocation (preferred) accepts a sequential s of sequentials containing record field values followed by a record constructor ->rec.

Throws an exception:

  1. If key/fields don't exactly match, or
  2. If a value is not unique within its column.

Example, 1-arity consuming a sequential of hash-maps:

(look-up [{:name "rose" :color :red :id 101}
          {:name "hibiscus" :color :orange :id 102}
          {:name "sunflower" :color :sunflower :id 103}])

Example, 2-arity consuming a sequential of sequentials containing field values plus a record constructor (preferred):

(defrecord Flower [flower color id])

(look-up [["rose" :red 101]
          ["hibiscus" :orange 102]
          ["sunflower" :yellow 103]]
         ->Flower)
Returns a [[LookUp]] instance which provides efficient look ups of symmetric
one-to-one relationships.

The 1-arity invocation accepts a sequential `s` of hash-maps. The 2-arity
invocation (preferred) accepts a sequential `s` of sequentials containing
record field values followed by a record constructor `->rec`.

Throws an exception:

1. If key/fields don't exactly match, or
2. If a value is not unique within its column.

Example, 1-arity consuming a sequential of hash-maps:
```clojure
(look-up [{:name "rose" :color :red :id 101}
          {:name "hibiscus" :color :orange :id 102}
          {:name "sunflower" :color :sunflower :id 103}])
```

Example, 2-arity consuming a sequential of sequentials containing field values
plus a record constructor (preferred):
```clojure
(defrecord Flower [flower color id])

(look-up [["rose" :red 101]
          ["hibiscus" :orange 102]
          ["sunflower" :yellow 103]]
         ->Flower)
```
raw docstring

LookUpcljprotocol

Methods for arranging symmetric one-to-one relationships and performing efficient look ups. Use look-up to create an instance.

Sample data for the following examples:

(defrecord Flower [name color id])

(def flowers (look-up [["rose" :red 101]
                       ["hibiscus" :orange 102]
                       ["sunflower" :yellow 103]]
                      ->Flower))
Methods for arranging symmetric one-to-one relationships and performing
efficient look ups. Use [[look-up]] to create an instance.

Sample data for the following examples:

```clojure
(defrecord Flower [name color id])

(def flowers (look-up [["rose" :red 101]
                       ["hibiscus" :orange 102]
                       ["sunflower" :yellow 103]]
                      ->Flower))
```

expansionclj

(expansion this)

Returns a hash-map of the expanded key-vals which enable efficient look ups.

Example:

(expansion flowers)
Returns a hash-map of the expanded key-vals which enable efficient look
ups.

Example:
```clojure
(expansion flowers)
```

get-rowclj

(get-row this col val)
(get-row this col val not-found)

Returns the row containing value val located in column col.

Example query: Return the row from flowers whose :name is "rose".

(get-row flowers :name "rose")
;; => #one_see.Flower{:name "rose", :color :red, :id 101}
Returns the row containing value `val` located in column `col`.

Example query: *Return the row from `flowers` whose `:name` is `"rose"`.*
```clojure
(get-row flowers :name "rose")
;; => #one_see.Flower{:name "rose", :color :red, :id 101}
```

get-valclj

(get-val this col-1 val-1 col-2)
(get-val this col-1 val-1 col-2 not-found)

Efficiently finds the row whose val-1 is located in column col-1, then returns val-2 located in col-2 of that row. If not found, returns nil or not-found.

get-val provides the invoke implementation of the clojure.lang.IFn interface, so a LookUp instance in the function position delegates to get-val.

Example query: Return the value of :id of the row whose :name is "rose"?

Example, explicit invocation:

(get-val flowers :name "rose" :id)
;; => 101

Example, implicit invocation:

(flowers :name "rose" :id)
;; => 101
Efficiently finds the row whose `val-1` is located in column `col-1`, then
returns `val-2` located in `col-2` of that row. If not found, returns `nil` or
`not-found`.

`get-val` provides the `invoke` implementation of the `clojure.lang.IFn`
interface, so a `LookUp` instance in the function position delegates to
`get-val`.


Example query: *Return the value of `:id` of the row whose `:name` is
`"rose"`?*

Example, explicit invocation:
```clojure
(get-val flowers :name "rose" :id)
;; => 101
```

Example, implicit invocation:
```clojure
(flowers :name "rose" :id)
;; => 101
```

sizeclj

(size this)

Returns an array-map of a LookUp instance's row and column counts.

Example:

(size flowers)
;; => {:n-rows 3, :n-cols 3}
Returns an array-map of a `LookUp` instance's row and column counts.

Example:
```clojure
(size flowers)
;; => {:n-rows 3, :n-cols 3}
```

tableclj

(table this)

Returns the original data in tabular form, as provided to look-up.

Example:

(table flowers)
Returns the original data in tabular form, as provided to [[look-up]].

Example:
```clojure
(table flowers)
```
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close