The documentation for comp
states that it starts with the rightmost function, applies the arguments to it, then gives the result to the next function and so on. Hence here the numbers are added first then str
is applied to the integer 16:
((comp str +) 8 8) ;;=> "16"
This code is from example 7 in the core.async
webinar:
mouse (events->chan js/window EventType.MOUSEMOVE
(chan 1
(comp (map mouse-loc->vec)
(filter (fn [[_ y]] (zero? (mod y 5)))))))
Here a stream of mouse events are the arguments. They are first converted into a pair (tuple 2 vector) and then these pairs are filtered. The map
function (which happens to be a transducer) needs to receive the mouse event before the filter
function, and obviously that is what is actually happening because this code works. So why is the first operation (the map
function) not the rightmost function argument to comp
?
Answer In the video at 25:30 Rich Hickey says "transducers ruin comp
or something like that" - after that he explains the issue. Thanks @nblumoe