This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-16
Channels
- # beginners (115)
- # boot (13)
- # boot-dev (13)
- # chestnut (1)
- # cider (1)
- # clara (10)
- # cljs-dev (21)
- # cljsjs (1)
- # cljsrn (2)
- # clojure (120)
- # clojure-dusseldorf (2)
- # clojure-greece (13)
- # clojure-ireland (1)
- # clojure-italy (3)
- # clojure-nlp (3)
- # clojure-russia (2)
- # clojure-spec (13)
- # clojure-uk (82)
- # clojured (5)
- # clojurescript (47)
- # core-async (2)
- # core-logic (8)
- # cursive (45)
- # datomic (2)
- # editors (1)
- # emacs (39)
- # fulcro (166)
- # graphql (1)
- # hoplon (16)
- # keechma (5)
- # off-topic (202)
- # perun (4)
- # protorepl (7)
- # re-frame (28)
- # reagent (13)
- # ring (27)
- # ring-swagger (16)
- # rum (1)
- # shadow-cljs (25)
- # spacemacs (20)
- # sql (141)
- # yada (4)
is there a way to compose accumulators outside of writing a custom reducer? e.g., I want to get the latest timestamp
of all
facts, so some combination of (acc/all)
and (acc/max :tx)
@dadair there isn’t anything directly for that. On a case by case you may able to get the behavior you want from an accumulator like the max above.
If you had a unique ID on all facts for example, you could just do ?l <- (acc/max :tx) :from [A (= id? ?id)]
I’m not sure that makes much sense though. acc/max is intended to find the max among all facts. Accumulators are mostly for reasoning about aggregates. I may have misunderstood your usage you were looking for.
The rule engine I work on takes the general from (state, action) -> actions
, where action
and actions
are actions to perform (in aggregate) to transition state
to a new state (basically the RE is a reduce, but instead of reducing to a new state, it returns “diff” operations through querying the resulting state that external service(s) can use to transition the state). A difficulty that I’ve had in general with this pattern is that I need to track changes to state
as rules propagate, and then insert output actions based on those changes. So for example, given an initial entity A {:id 1, :x true}
, there may be cascading changes over the (short) life of the session that cause it to transition to any number of {true,false}
values. I always want the stable result, so I have added tx
values to track “time”. Given that, I may have a rule that “subscribes” to a number of those facts (e.g., all
:id
s), but I want the max
:tx
of each of those entities.
In summary: [?entities <- (acc/all) :from [TimestampedEntity]] ;; ?entities => [{:id 1, :x true, :tx 1} {:id 1, :x false, :tx 2} {:id 2, :x true, :tx 3}]
but I only want the latest :tx
for each unique entity, so desired: ?entities => [{:id 1, :x false, :tx 2} {:id 2, :x true, :tx 3}]
e.g., to calculate a ratio of true entities over all entities (but only for their final states)