[geary/wip/713891-traversable: 3/12] Adding some more methods I know we'll need
- From: Charles Lindsay <clindsay src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/713891-traversable: 3/12] Adding some more methods I know we'll need
- Date: Thu, 12 Dec 2013 02:57:46 +0000 (UTC)
commit 05fe09715b44617e7fddd3933fbeff9726368e54
Author: Charles Lindsay <chaz yorba org>
Date: Wed Dec 11 16:56:27 2013 -0800
Adding some more methods I know we'll need
src/engine/util/util-traversable.vala | 30 ++++++++++++++++++++++++++++++
1 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/src/engine/util/util-traversable.vala b/src/engine/util/util-traversable.vala
index b4889ff..3d5be23 100644
--- a/src/engine/util/util-traversable.vala
+++ b/src/engine/util/util-traversable.vala
@@ -60,6 +60,36 @@ public class Iterable<G> : BaseObject {
.map<A>(x => { return (A) x; }));
}
+ public G? first() {
+ if (!i.next())
+ return null;
+ return i.get();
+ }
+
+ public G? first_matching(owned Gee.Predicate<G> f) {
+ foreach (G g in this) {
+ if (f(g))
+ return g;
+ }
+ return null;
+ }
+
+ public bool any(owned Gee.Predicate<G> f) {
+ foreach (G g in this) {
+ if (f(g))
+ return true;
+ }
+ return false;
+ }
+
+ public bool all(owned Gee.Predicate<G> f) {
+ foreach (G g in this) {
+ if (!f(g))
+ return false;
+ }
+ return true;
+ }
+
public Collection<G> to_collection(owned Gee.EqualDataFunc<G>? equal_func = null) {
return new Collection<G>(i, equal_func);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]