~pepe/eleanor

63270a2bc56761250f1f154b694cd49f2cb0f9f2 — Josef Pospíšil 2 months ago 1b19a27
Add flatvals point
3 files changed, 23 insertions(+), 12 deletions(-)

M eleanor/points.janet
M examples/bench.janet
M test/suite01.janet
M eleanor/points.janet => eleanor/points.janet +8 -0
@@ 117,6 117,14 @@

(def >:: `select alias` select)

(defn flatvals [base]
  ```
  Flattens the values of each member of the base.
  ```
  (def res @[])
  (loop [t :in base] (array/push res ;(values t)))
  res)

(defn change
  ```
  Changes base under the `key` to new `value`.

M examples/bench.janet => examples/bench.janet +5 -11
@@ 16,31 16,25 @@
  res)

(def db
  (init-db 233))
  (init-db 333))

(var r nil)
(def s (os/clock))
(print
  (length
    ((guide :clients (in-all :projects)
                 (all-by values) flatten (in-all :name)) db)))
  ((guide :clients (in-all :projects)
          (all-by values) flatten (in-all :name) length) db))
(repeat 10
  ((guide :clients (in-all :projects)
                 (all-by values) flatten (in-all :name) trace-elapsed) db))
          (all-by values) flatten (in-all :name) trace-elapsed) db))

(printf "%fms" (* 1000 (- (os/clock) s)))


(def s (os/clock))

(defn valflat [base]
  (def res @[])
  (loop [t :in base] (array/push res ;(values t)))
  res)

(repeat 10
  ((guide :clients (in-all :projects)
                 valflat (in-all :name) trace-elapsed) db))
          flatvals (in-all :name) trace-elapsed) db))

(printf "%fms" (* 1000 (- (os/clock) s)))


M test/suite01.janet => test/suite01.janet +10 -1
@@ 185,6 185,15 @@
  "view all with collected then drop with aliases")

(assert
  (deep= ((guide (<- (=> :priorities)) :projects (<-)
                 values (>: :tasks) flatvals
                 (<o> display-name) <x) db)
         @["@Kamilah #2 - finish is low priority"
           "@Eleanor #3 - start is high priority"
           "@Eleanor #4 - add plus is low priority"])
  "flatvals")

(assert
  (deep= ((guide :projects values (all-by (select :uuid :title))) db)
         @[@{:uuid "0" :title "Kamilah"} @{:uuid "1" :title "Eleanor"}])
  "select")


@@ 269,7 278,7 @@
    "Elapsed: 0."
    ((capture-stderr
       ((guide (<- (=> :priorities)) trace-elapsed
               :projects (<-) values (>: :tasks) (>fn values) flatten
               :projects (<-) values (>: :tasks) flatvals
               drop-elapsed (<o> display-name) trace-elapsed <x) db)) 1))
  "trace elapsed time")