missionary

awb99 2024-07-07T17:27:04.765089Z

I have a Problem consuming a flow. I created a scheduler that emits an instant every x second. It works when I use m/reduce. But this gibes me back all the evaluations at the End of the seq. I want to eval every event that Comes along. This is the repo: https://github.com/clojure-quant/missionary-test/blob/main/src/demo/scheduler.clj

awb99 2024-07-12T20:22:23.162359Z

Thanks! I now have my mental model to always provide initial value to m/reduce. It avoids lots of errors. At least it happened to me a lot.

awb99 2024-07-11T23:40:10.317369Z

Yes. My confusion comes from the case where no initial value is given. When initial value is passed then it expects a normal reducing function of 2 args. If there is no initial value passed .. then clojure.core reduce would call the reducing function with 2 args (the first arg which normally would be the state is passed the first item in the collection). Missionary in this case needs an additional arity. Clojure transducers have 0 1 and 2 arities. Missionary reducer function having 0 and 2 arities is something in between.

leonoel 2024-07-12T06:50:34.204949Z

clojure's reduce uses rf's arity 0 too, when initial state is not provided and the collection is empty

leonoel 2024-07-12T06:57:37.569209Z

I agree we're missing a word for this kind of object, but "transducing function" doesn't type check to me, this is a standalone concept that is useful without transducers

leonoel 2024-07-08T09:37:58.580819Z

I disagree with your naming proposition, in clojure core implementation rf is used for reducing functions (i.e. the function passed to reduce) and xf is used for transducers (i.e. reducing function transformers). Arity 0 is optional and only used when the initial state is not provided.

leonoel 2024-07-07T20:29:52.361509Z

print-time returns a flow, it cannot be consumed with ?

leonoel 2024-07-07T20:31:07.771949Z

use m/reduce like in the working example

awb99 2024-07-07T23:37:40.405529Z

Thanks @leonoel I somehow hesitated to reduce over an Infinite collection. You should document it better that m/reduce is the only was to start a flow. It is not intuitive (at least to me). Also I think reduce does not receive a reduce function as argument but a transducer function (the 0 Argument call is usually used in a transducer; a reducer function always has 2 args (result and value).

awb99 2024-07-07T23:38:24.988489Z

So use xf instead of rf as the variable name.

awb99 2024-07-07T23:41:23.503529Z

The gratis News is this: I am using chime libraey for scheduling. With missionary this need falls away. And this with better supervision. You really built a pretty powerful library!

💪 1