Re: Gee Functional iterators



On 13/07/10 17:31, Martin DeMello wrote:
> And the problem seems to be that generics and delegates mix poorly
> (that is, we could possibly workaround
> https://bugzilla.gnome.org/show_bug.cgi?id=546305 if we only had
> proper support for delegates with generic input and return types). Is
> that correct? I'm still getting to grips with the way vala does
> generics.

Generics in delegates are about to come. So you can design with them in
mind.

For instance, I guess that something like the following could work
(2-minutes code):

public <G,T> delegate T MapFunc(G element);

public interface Iterable<G> {

	[...]

  public abstract <T> Iterable<T>
      map (MapFunc<G,T> func, List<T> list = null);
}

public abstract class AbstractList<G> : List<G> {

	[...]

  protected abstract <T> List<T> create_empty ();

  public <T> Iterable<T>
      map (MapFunc<G,T> func, List<T>? list = null) {
    List<G> result = list ?? create_empty<T> ();
    foreach (T element in this) {
      list.add (func (element));
    }
  }
}

But please could you first define the set of operators you would like so
that we can discuss them ? I would be glad to not bloat the existing API
with too many methods but a correct method set, as there still other
features to come.

Best regards, Didier.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]