Liking cljdoc? Tell your friends :D

one-see.core

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

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

RowStackcljprotocol

Operations for manipulating a sequential of hashmaps/records. Every push-ed hashmap/record:

  1. Must include exactly the keys/fields of existing elements, if any, and
  2. The value of each field must be unique from those of the other existing elements.

Instances implement the invoke methods of clojure.lang.IFn with get-val.

Sample data for following examples.

(defrecord Flower [flower color id])

(def flowers (stack-rows [["rose" :red 101]
                          ["hibiscus" :orange 102]
                          ["sunflower" :yellow 103]]
                         ->Flower))
Operations for manipulating a sequential of hashmaps/records. Every `push`-ed
hashmap/record:

1. Must include exactly the keys/fields of existing elements, if any, and
2. The value of each field must be unique from those of the other existing
elements.

Instances implement the `invoke` methods of `clojure.lang.IFn` with
[[get-val]].

Sample data for following examples.
```clojure
(defrecord Flower [flower color id])

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

allclj

(all this)

Returns all rows of the internal representation of a RowStack instance, a plain Clojure sequential of hashmaps/records.

Note: The returned sequential will not maintain a RowStack instance's uniqueness guarantees.

Example:

(all flowers)
;; => [#one_see.core.Flower{:flower "rose", :color :red, :id 101}
;;     #one_see.core.Flower{:flower "hibiscus", :color :orange, :id 102}
;;     #one_see.core.Flower{:flower "sunflower", :color :yellow, :id 103}]
Returns all rows of the internal representation of a `RowStack` instance, a
plain Clojure sequential of hashmaps/records.

 Note: The returned sequential will not maintain a `RowStack` instance's
 uniqueness guarantees.

 Example:
 ```clojure
 (all flowers)
 ;; => [#one_see.core.Flower{:flower "rose", :color :red, :id 101}
 ;;     #one_see.core.Flower{:flower "hibiscus", :color :orange, :id 102}
 ;;     #one_see.core.Flower{:flower "sunflower", :color :yellow, :id 103}]
 ```

deleteclj

(delete this m)

Returns a new RowStack instance with hashmap/record m removed.

Example:

(all (delete flowers (->Flower "hibiscus" :orange 102)))
;; => [#one_see.core.Flower{:flower "rose", :color :red, :id 101}
;;     #one_see.core.Flower{:flower "sunflower", :color :yellow, :id 103}]
Returns a new `RowStack` instance with hashmap/record `m` removed.

Example:
```clojure
(all (delete flowers (->Flower "hibiscus" :orange 102)))
;; => [#one_see.core.Flower{:flower "rose", :color :red, :id 101}
;;     #one_see.core.Flower{:flower "sunflower", :color :yellow, :id 103}]
```

get-rowclj

(get-row this field value)
(get-row this field value not-found)

Returns the row, a hashmap/record, for which field is associated to value. If none match, returns nil or not-found.

Example:

(get-row flowers :id 103)
;; => #one_see.core.Flower{:flower "sunflower", :color :yellow, :id 103}
Returns the row, a hashmap/record, for which `field` is associated to
`value`. If none match, returns `nil` or `not-found`.

 Example:
 ```clojure
 (get-row flowers :id 103)
 ;; => #one_see.core.Flower{:flower "sunflower", :color :yellow, :id 103}
 ```

get-valclj

(get-val this field-1 value-1 field-2)
(get-val this field-1 value-1 field-2 not-found)

From the row whose field-1 is value-1, returns the value associated to field-2.

Example, explicit invocation:

(get-val flowers :color :orange :flower)
;; => "hibiscus"

get-val supplies the invoke method, so a RowStack instance in the function postion consumes this argument sequence.

Example, implicit invocation:

(flowers :color :orange :flower)
;; => "hibiscus"
From the row whose `field-1` is `value-1`, returns the value associated to
 `field-2`.

 Example, explicit invocation:
 ```clojure
 (get-val flowers :color :orange :flower)
 ;; => "hibiscus"
 ```

`get-val` supplies the `invoke` method, so a `RowStack` instance in the
function postion consumes this argument sequence.

 Example, implicit invocation:
 ```clojure
 (flowers :color :orange :flower)
 ;; => "hibiscus"
 ```

pushclj

(push this m)

Returns a new RowStack instance with appended hashmap/record m if and only if the fields exactly match and the values are unique from all other rows. Otherwise, throws an exception.

Prefer the higher-level stack-rows for constructing an instance.

Example:

(all (push flowers (->Flower "daffodil" :white 104)))
;; [#one_see.core.Flower{:flower "rose", :color :red, :id 101}
;;  #one_see.core.Flower{:flower "hibiscus", :color :orange, :id 102}
;;  #one_see.core.Flower{:flower "sunflower", :color :yellow, :id 103}
;;  #one_see.core.Flower{:flower "daffodil", :color :white, :id 104}]
Returns a new `RowStack` instance with appended hashmap/record
`m` if and only if the fields exactly match and the values are unique from all
other rows. Otherwise, throws an exception.

Prefer the higher-level [[stack-rows]] for constructing an instance.

Example:
```clojure
(all (push flowers (->Flower "daffodil" :white 104)))
;; [#one_see.core.Flower{:flower "rose", :color :red, :id 101}
;;  #one_see.core.Flower{:flower "hibiscus", :color :orange, :id 102}
;;  #one_see.core.Flower{:flower "sunflower", :color :yellow, :id 103}
;;  #one_see.core.Flower{:flower "daffodil", :color :white, :id 104}]
```

sizeclj

(size this)

Returns an array-map of a RowStack instance's row and column count as {:n-rows <integer> :n-cols <integer>}.

Example:

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

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

stack-rowsclj

(stack-rows s)
(stack-rows s ->rec)

Returns a RowStack instance. If given only a sequential s of hashmaps, directly push-es the elements of s. If given a sequential s of field values and a record constructor ->rec, invokes the constructor with the elements of s before push-ing.

Throws an exception if key/fields don't exactly match or if a value is not unique within its column.

Example, 1-arity consuming hash-maps:

(stack-rows [{:flower "rose" :color :red :id 101}
             {:flower "hibiscus" :color :orange :id 102}
             {:flower "sunflower" :color :yellow :id 103}])

Example, 2-arity consuming records:

(defrecord flower-color [flower color id])

(stack-rows [["rose" :red 101]
             ["hibiscus" :orange 102]
             ["sunflower" :yellow 103]] ->flower-color)
Returns a `RowStack` instance. If given only a sequential `s` of hashmaps,
directly [[push]]-es the elements of `s`. If given a sequential `s` of field
values and a record constructor `->rec`, invokes the constructor with the
elements of `s` before `push`-ing.

Throws an exception if key/fields don't exactly match or if a value is not
unique within its column.

Example, 1-arity consuming hash-maps:
```clojure
(stack-rows [{:flower "rose" :color :red :id 101}
             {:flower "hibiscus" :color :orange :id 102}
             {:flower "sunflower" :color :yellow :id 103}])
```

Example, 2-arity consuming records:
```clojure
(defrecord flower-color [flower color id])

(stack-rows [["rose" :red 101]
             ["hibiscus" :orange 102]
             ["sunflower" :yellow 103]] ->flower-color)
```
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