Hi,
out of curiosity I did an initial port of Clojure's Reducers library. I've just pushed it to the public repository. It is by no means complete or optimized. In fact, I ask you for your impressions and ideas where to go from here.
So, what's in here?
Reducers builds upon the simple abstraction that a collection is a reducible object, i.e., an object that understands #reduce:init:. It provides fundamental collection operations similar to classical methods, e.g., like #collect:, but offers specific advantages:
- Reducers are composable and reusable.
- Memory efficiency, since no intermediate collections are constructed.
- Enable collection operations on custom types simply by implementing #reduce:init:.
- Possibility of parallel operations on collections, e.g., with Polycephaly 2.
For example, the sum of odd numbers could be computed like this:
| col red |
col := (1 to: 10**6).
(Reducer filter: #odd from: col) reduce: #+ init: 0.
"composition of reducers works like this:"
red := (Reducer filter: #odd) <> (Reducer map: #squared).
(red from: col) reduce: #+ init: 0.
Some questions:
1. What do you think of the current API?
2. How could one improve the execution time? (Optimizations to the construction of the (nested) blocks?)
Have fun!
Steffen
_______________________________________________
vwnc mailing list
vwnc@cs.uiuc.eduhttp://lists.cs.uiuc.edu/mailman/listinfo/vwnc