~pepe/eleanor

03c498ca3d391ba0cad919f924031cdbcc251468 — Josef Pospíšil 3 months ago 5c4fd8a
Add change-fn point
2 files changed, 11 insertions(+), 0 deletions(-)

M eleanor/points.janet
M test/suite01.janet
M eleanor/points.janet => eleanor/points.janet +7 -0
@@ 132,6 132,13 @@
  [key value]
  (fn change [i] (put i key value)))

(defn fn-change
  ```
  Changes base under the `key` to result of running `fun` on its value.
  ```
  [key fun]
  (fn fn-change [i] (update i key fun)))

(defn add
  ```
  Returns function that will push `value` into base.

M test/suite01.janet => test/suite01.janet +4 -0
@@ 210,6 210,10 @@
                 "completed"))
        "mutate db - change state")

(assert (deep= ((guide (fn-change :counter inc)) @{:counter 0})
               @{:counter 1})
        "change-fn")

(assert (do ((guide :projects "0" :tasks
                    (change "5" @{:uuid "5"
                                  :name "add minus"