GNOME Bugzilla – Bug 589968
Adding functional iterators
Last modified: 2012-08-12 07:31:18 UTC
Adding functional iterators like iter, map, fold, ... with tail recursion (if possible). Some examples: Node<K, V> map_func(K key, V value) { ... } Map<K, V> m = new TreeMap(); Map<K, V> m2 = m.map(map_func) void iter_func(G val) { ... } List<G> l = new ArrayList(); l.iter(iter_func); G map_func(G val) { ... } List<G> l2 = l.map(map_func); T fold_func(G val, T init) { ... } T t = l2.fold(fold_func, new T()); Definitely examples need to be improved but this kind of features can increase significantly code readability and maintainability for library users.
Loving functional programming I agree. However there are several ways: - Spam the interface with additional functions breaking API in each update in process (not nice) - Wait till bug #546305 is implemented and do it in nice GObject-like way - Add the Utils or Functional classes and add methods accordingly - Add the Foldable or similar Haskell-like interfaces (possibly running into bug #596549): // TODO: Find some less scary (i.e. not category-releated[1]) name public delegate <A, B> B FMap (A); public interface Functor<F> { public F<B> map(F<A>, FMap<A, B>); } Anyway to do this properly (not by void * passing) I add dependency on 592993. [1] While FP enters mainstream it is often not exposed all internals. For example F# contains monads (one one scary Haskell-related names ;) ) without calling it by this name.
This is not a "real" blocker but it makes the use of stream in non-generic way (including in test) much harder (so much that in such cases it outweights it's benefits). Implementation is finished with minor exceptions.
*** Bug 666480 has been marked as a duplicate of this bug. ***
This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.