On Fri, Aug 20, 2010 at 8:06 PM, Andrea Del Signore <[email protected]> wrote:
>
> If you want to use a lambda this is what I came with (see the map
> function):
>
>  public void map<I, T>(DFunc<I, T> fn, Gee.List<T> acc) {
>    foreach (G i in this) {
>      acc.add(fn(i));
>    }
>  }


Beautiful, thanks :)

martin

> }
>
> public class EnumerableList<G> : Gee.ArrayList<G>, Enumerable<G> {
> }
>
> public string f(int i) {
>  return "%d".printf(i);
> }
>
> public static int main(string[] args) {
>  var a = new EnumerableList<int> ();
>  a.add(1);
>  a.add(2);
>  a.add(3);
>  var b = new Gee.ArrayList<string> ();
>  a.map<int, string>(f , b);
>  foreach (string i in b) {
>    stdout.printf("-- %s --\n", i);
>  }
>  b.clear ();
>  //using a lambda
>  a.map<int, string>((i) => { return "result: %d".printf (i); } , b);
>  foreach (string i in b) {
>    stdout.printf("-- %s --\n", i);
>  }
>
>  return 0;
> }
>
> HTH,
>        Andrea
>
>
>
_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to