After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 589968 - Adding functional iterators
Adding functional iterators
Status: RESOLVED FIXED
Product: libgee
Classification: Platform
Component: general
git master
Other All
: Normal enhancement
: 0.7
Assigned To: libgee-maint
libgee-maint
: 666480 (view as bug list)
Depends on: 592993 622570 640330 653403 666480
Blocks:
 
 
Reported: 2009-07-28 07:46 UTC by Julien Peeters
Modified: 2012-08-12 07:31 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Julien Peeters 2009-07-28 07:46:03 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.
Comment 1 Maciej (Matthew) Piechotka 2010-07-10 15:06:13 UTC
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.
Comment 2 Maciej (Matthew) Piechotka 2011-06-25 16:58:19 UTC
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.
Comment 3 Maciej (Matthew) Piechotka 2012-01-16 23:48:09 UTC
*** Bug 666480 has been marked as a duplicate of this bug. ***
Comment 4 Maciej (Matthew) Piechotka 2012-08-12 07:31:18 UTC
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.