www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Clojure transducers

reply "Puming" <zhaopuming gmail.com> writes:
Clojure is introducing a new way of composing functions (reducers 
this time), called transducers. It looks similar to 
composition/binding of functions, but somehow different. My 
functional-fu is not that deep to understand the statement 
"transducers are as fundamental as function composition" but it 
seems quite interesting. What is D's attitude toward this concept?

Here is a blog I read about transducers today:

http://thecomputersarewinning.com/post/Transducers-Are-Fundamental/
Aug 30 2014
parent Philippe Sigaud via Digitalmars-d <digitalmars-d puremagic.com> writes:
 What is D's attitude toward this concept?
Hickey's original announcement is also interesting to read. Elegant, as always. It seems to me that ranges and range algorithms in D already permit this composition of actions, without the creation of intermediate structures: import std.algorithm; import std.functional: pipe; alias incsum = pipe!( map!(x => x+1), reduce!((x,y) => x+y) ); alias filtermap = pipe!( filter!(x => x%2==0), map!(x => x+1) ); alias mapfilter = pipe!( map!(x => x+1), filter!(x => x%2==0) ); void main() { auto sequence = iota(10); writeln(incsum(sequence)); // 55 writeln(filtermap(sequence)); // [1, 3, 5, 7, 9] writeln(mapfilter(sequence)); // [2, 4, 6, 8, 10] }
Aug 31 2014