Gee Implementing helper functions



Hi,

I am currently playing around with vala and gee and have some questions
about them.

I want to implement some helper functions like:
- void each (each_delegate func)
- G find (find_delegate func)
- ArrayList<G> find_all (find_delegate func)
- map, fold, ...


I tried to do something like this:

// code

using Gee;

public class MyList<G>: ArrayList<G>{
	public delegate void EachFunc (G i);
	public void each (EachFunc each_func) {
		var iter = this.iterator();
		iter.first();
		do {
			each_func (iter.get());
		} while (iter.next());
	}
}

void print( int i) {stdout.printf ("%d\n", i);}


static int main (string[] args) {

    var list = new MyList<int> ();
    list.add (1);
    list.add (2);
    list.add (5);
    list.add (4);
    list.each((i) => {print( (int) i);});
    return 0;
}

// end code


Of course this each function could be easily replaced by a foreach
loop, but its just a test.

It raised some questions:
- Is there some function to do what I want in libgee that I have not
  seen?
- Is this a good approch?
- Is there any way to do without a wrapper like MyList and use directly
  the ArrayList?
- Is there any way to do without the (int) casting on line
  list.each(...)?

Thanks for your attention.

-- 
Nicolas Rassat


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