cognitect-labs / transducers-ruby Goto Github PK
View Code? Open in Web Editor NEWTransducers for Ruby
License: Apache License 2.0
Transducers for Ruby
License: Apache License 2.0
I've implemented a few custom transducing functions using this library (and your excellent JavaScript port).
After following the documentation here: http://www.rubydoc.info/gems/transducers/Transducers
Is their an idiomatic way of passing in additional parameters to transducing functions? E.g. perhaps if you're operating on an array of hashes, you could supply the hash key that the transducing function would use.
That said, I may be missing some fundamental concepts of how transducers are designed to work (and I have not used them in Clojure yet).
Not to be a Debby Downer, but this doesn't feel at all like idiomatic Ruby.
I think the biggest improvement would be to mix in a transduce
method into Enumerable
, with a signature closer to Enumerable#reduce
. The other thing that feels wrong is that almost everything is a class method. It seems like a more idiomatic way to do it would be with a block using instance_eval
, so we could do something like:
(1..100).transduce([], :<<) do
filter(:even?)
map{ |n| n * 2 }
take(5)
end
For composabilitiy:
first_5_even_doubled = Transducer.compose do
filter(:even?)
map{ |n| n * 2 }
take(5)
end
(1..100).transduce([], :<<) do
first_5_even_doubled
end
I'll have to think about this some more, and see if I can contribute some code back to implement a more idiomatic way of doing this in Ruby, while keeping composability in mind.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.