cgrand / xforms

Extra transducers and reducing fns for Clojure(script)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

just a question

lifeiscontent opened this issue · comments

commented

@cgrand sorry to bother you, I'm not familiar with clojure so I was hoping you could explain the concept of how a sort transducer works maybe in pseudo code so I could implement one in JavaScript.

thanks in advance!

There’s no magic: the whole input is buffered, the sort only occurs when the upstream completes.

(closing as just a question, you can still comment to ask for more details)

commented

@cgrand I see, so it's just a lazy transform? is it not composed? e.g. ['b', 'a'].map(x => x.toUpperCase()).sort()

commented

@cgrand so in the case of composed vs not composed.

in a composed set of transforms everything is done in a single loop.

with a set of uncomposed transforms everything happens in a separate loop.

e.g.:

map -- loop 1
sort -- loop 2

I guess what I'm wondering here is if it's possible to both map/sort items within a single loop.

commented

@cgrand ah ok, so the sort transducer you've implemented is just a thing to have for composability. Makes sense. Thanks for spending the time to talk over it with me. Much appreciated!