*/
public abstract Iterator<G> iterator ();
- public virtual void foreach (ForallFunc<G> f) {
- iterator ().foreach (f);
+ public virtual bool foreach (ForallFunc<G> f) {
+ return iterator ().foreach (f);
}
public virtual Iterator<A> stream<A> (owned StreamFunc<G, A> f) {
/**
* {@inheritDoc}
*/
- public virtual void foreach (ForallFunc<Map.Entry<K,V>> f) {
- iterator ().foreach (f);
+ public virtual bool foreach (ForallFunc<Map.Entry<K,V>> f) {
+ return iterator ().foreach (f);
}
/**
return outer.get_key ();
}
- public void foreach (ForallFunc<K> f) {
+ public bool foreach (ForallFunc<K> f) {
if (inner != null && outer.valid) {
- K key = outer.get_key ();
- inner.foreach ((v) => {f (key);});
+ K key = outer.get_key ();
+ if (!inner.foreach ((v) => {return f (key);})) {
+ return false;
+ }
outer.next ();
}
- outer.foreach ((key, col) => {
- col.foreach ((v) => {f (key);});
+ return outer.foreach ((key, col) => {
+ return col.foreach ((v) => {return f (key);});
});
}
}
return inner.get ();
}
- public void foreach (ForallFunc<V> f) {
+ public bool foreach (ForallFunc<V> f) {
if (inner != null && outer.valid) {
- inner.foreach (f);
+ if (!inner.foreach (f)) {
+ return false;
+ }
outer.next ();
}
- outer.foreach ((key, col) => {
- col.foreach (f);
+ return outer.foreach ((key, col) => {
+ return col.foreach (f);
});
}
}
}
}
- public void foreach (ForallFunc<G> f) {
- if(!_removed && _iter.valid)
- f(_iter.get_key());
- if(_iter.valid)
- for(int i = _pending - 1; i > 0; --i)
- f(_iter.get_key());
- while(_iter.next())
- for(int i = _iter.get_value(); i > 0; --i)
- f(_iter.get_key());
- _pending = 0;
+ public bool foreach (ForallFunc<G> f) {
+ if (_iter.valid) {
+ if (!_removed) {
+ if (!f(_iter.get_key())) {
+ return false;
+ }
+ }
+ for(int i = _pending - 1; i >= 0; --i) {
+ if (!f(_iter.get_key())) {
+ _pending = i;
+ return false;
+ }
+ }
+ }
+ while(_iter.next()) {
+ for(int i = _iter.get_value() - 1; i >= 0; --i) {
+ if (!f(_iter.get_key())) {
+ _removed = false;
+ _pending = i;
+ return false;
+ }
+ }
+ }
_removed = false;
+ _pending = 0;
+ return true;
}
}
}
}
}
- public void foreach (ForallFunc<G> f) {
+ public bool foreach (ForallFunc<G> f) {
assert (_stamp == _list._stamp);
- if (_index < 0 || _removed)
+ if (_index < 0 || _removed) {
_index++;
+ }
while (_index < _list._size) {
- f (_list._items[_index]);
+ if (!f (_list._items[_index])) {
+ return false;
+ }
_index++;
}
- _index = _list._size;
+ _index = _list._size - 1;
+ return true;
}
}
}
public bool read_only { get {return false;} }
- public void foreach (ForallFunc<G> f) {
+ public bool foreach (ForallFunc<G> f) {
assert (_queue._stamp == _stamp);
- if(!valid) {
+ if (!valid) {
_offset++;
_removed = false;
}
- for(int i = _offset; i < _queue._length; i++) {
- f (_queue._items[(_queue._start + i) % _queue._items.length]);
+ for (int i = _offset; i < _queue._length; i++) {
+ if (!f (_queue._items[(_queue._start + i) % _queue._items.length])) {
+ _offset = i;
+ return false;
+ }
}
+ return true;
}
private ArrayQueue _queue;
_index++;
}
- public new void foreach (ForallFunc<G> f) {
+ public new bool foreach (ForallFunc<G> f) {
HazardPointer.Context ctx = new HazardPointer.Context ();
- if (_started && !_removed)
- f (HazardPointer.get_pointer<G> (&_curr._data));
+ if (_started && !_removed) {
+ if (!f (HazardPointer.get_pointer<G> (&_curr._data))) {
+ return false;
+ }
+ }
Node<G>? _old_prev = _removed ? _prev : null;
while (Node.proceed<G> (ref _prev, ref _curr)) {
if (_removed)
_removed = false;
_started = true;
_index++;
- f (HazardPointer.get_pointer<G> (&_curr._data));
+ if (!f (HazardPointer.get_pointer<G> (&_curr._data))) {
+ return false;
+ }
}
+ return true;
}
private bool _started;
assert_not_reached ();
}
- public void foreach(ForallFunc<K> f) {
+ public bool foreach(ForallFunc<K> f) {
if (_node != null) {
- f(_node.key);
- if(_next == null)
+ if (!f(_node.key)) {
+ return false;
+ }
+ if(_next == null) {
_next = _node.next;
+ }
}
do {
while(_next != null) {
_node = _next;
- f(_node.key);
+ if (!f(_node.key)) {
+ return false;
+ }
_next = _next.next;
}
- if (_index + 1 < _map._array_size)
+ if (_index + 1 < _map._array_size) {
_next = _map._nodes[++_index];
- else
- break;
+ } else {
+ return true;
+ }
} while(true);
}
}
assert_not_reached ();
}
- public void foreach(ForallFunc<V> f) {
+ public bool foreach(ForallFunc<V> f) {
if (_node != null) {
- f(_node.value);
- if(_next == null)
+ if (!f(_node.value)) {
+ return false;
+ }
+ if(_next == null) {
_next = _node.next;
+ }
}
do {
while(_next != null) {
_node = _next;
- f(_node.value);
+ if (!f(_node.value)) {
+ return false;
+ }
_next = _next.next;
}
- if (_index + 1 < _map._array_size)
+ if (_index + 1 < _map._array_size) {
_next = _map._nodes[++_index];
- else
- break;
+ } else {
+ return true;
+ }
} while(true);
}
}
assert_not_reached ();
}
- public void foreach(ForallFunc<Map.Entry<K,V>> f) {
+ public bool foreach(ForallFunc<Map.Entry<K,V>> f) {
if (_node != null) {
- f(Entry<K,V>.entry_for<K,V> (_node));
- if(_next == null)
+ if (!f(Entry<K,V>.entry_for<K,V> (_node))) {
+ return false;
+ }
+ if(_next == null) {
_next = _node.next;
+ }
}
do {
while(_next != null) {
_node = _next;
- f(Entry<K,V>.entry_for<K,V> (_node));
+ if (!f(Entry<K,V>.entry_for<K,V> (_node))) {
+ return false;
+ }
_next = _next.next;
}
- if (_index + 1 < _map._array_size)
+ if (_index + 1 < _map._array_size) {
_next = _map._nodes[++_index];
- else
- break;
+ } else {
+ return true;
+ }
} while(true);
}
}
}
}
- public void foreach (ForallFunc<G> f) {
+ public bool foreach (ForallFunc<G> f) {
assert (_stamp == _set._stamp);
- if (_node != null)
- f (_node.key);
+ if (_node != null) {
+ if (!f (_node.key)) {
+ return false;
+ }
+ }
while (_index + 1 < _set._array_size || _next != null) {
if (_next != null) {
_node = _next;
- f (_node.key);
+ if (!f (_node.key)) {
+ return false;
+ }
_next = _node.next;
} else {
_index++;
_next = _set._nodes[_index];
}
}
+ return false;
}
}
}
Collection<ArrayList<FreeNode *>> temp = new ArrayList<ArrayList<FreeNode *>> ();
_queue.drain (temp);
_queue_mutex.unlock ();
- temp.foreach ((x) => {_global_to_free.add_all (x);});
+ temp.foreach ((x) => {_global_to_free.add_all (x); return true;});
}
try_free (_global_to_free);
}
}
}
- public void foreach (ForallFunc<G> f) {
+ public bool foreach (ForallFunc<G> f) {
assert (_stamp == _list._stamp);
if (!started) {
position = _list._head;
}
removed = false;
while (position != null) {
- f (position.data);
+ if (!f (position.data)) {
+ return false;
+ }
position = position.next;
}
position = _list._tail;
+ return true;
}
}
namespace Gee {
public delegate A FoldMapFunc<A, K, V> (K k, V v, owned A a);
- public delegate void ForallMapFunc<K, V> (K k, V v);
+ public delegate bool ForallMapFunc<K, V> (K k, V v);
}
/**
* Operation moves the iterator to last element in iteration. If iterator
* points at some element it will be included in iteration.
*/
- public new virtual void foreach (ForallMapFunc<K, V> f) {
- if (valid)
- f (get_key (), get_value ());
- while (next ())
- f (get_key (), get_value ());
+ public new virtual bool foreach (ForallMapFunc<K, V> f) {
+ if (valid) {
+ if (!f (get_key (), get_value ())) {
+ return false;
+ }
+ }
+ while (next ()) {
+ if (!f (get_key (), get_value ())) {
+ return false;
+ }
+ }
+ return true;
}
}
}
}
- public void foreach (ForallFunc<G> f) {
- if (valid)
- f (position.data);
- while (next ())
- f (position.data);
+ public bool foreach (ForallFunc<G> f) {
+ if (valid) {
+ if (!f (position.data)) {
+ return false;
+ }
+ }
+ while (next ()) {
+ if (!f (position.data)) {
+ return false;
+ }
+ }
+ return true;
}
}
}
/**
* {@inheritDoc}
*/
- public void foreach (ForallFunc<G> f) {
- _collection.foreach (f);
+ public bool foreach (ForallFunc<G> f) {
+ return _collection.foreach (f);
}
/**
get { return typeof (G); }
}
- public void foreach (ForallFunc<G> f) {
- _iter.foreach (f);
+ public bool foreach (ForallFunc<G> f) {
+ return _iter.foreach (f);
}
public Gee.Iterator<A> stream<A> (owned StreamFunc<A, G> f) {
/**
* {@inheritDoc}
*/
- public void foreach (ForallFunc<Map.Entry<K, V>> f) {
- _map.foreach (f);
+ public bool foreach (ForallFunc<Map.Entry<K, V>> f) {
+ return _map.foreach (f);
}
/**
namespace Gee {
public delegate A FoldFunc<A, G> (owned G g, owned A a);
- public delegate void ForallFunc<G> (owned G g);
+ public delegate bool ForallFunc<G> (owned G g);
public delegate Lazy<A>? UnfoldFunc<A> ();
public delegate Traversable.Stream StreamFunc<G, A> (Traversable.Stream state, owned Lazy<G>? g, out Lazy<A>? lazy);
public delegate A MapFunc<A, G> (owned G g);
[GenericAccessors]
public interface Gee.Traversable<G> : Object {
/**
- * Apply function to each element returned by iterator.
+ * Apply function to each element returned by iterator untill last element
+ * or function return ''false''.
*
* ''{@link Iterator} implementation:'' Operation moves the iterator
- * to last element in iteration. If iterator points at some element it
- * will be included in iteration.
+ * to last element in iteration or the first element that returned ''false''.
+ * If iterator points at some element it will be included in iteration.
+ *
+ * @return ''false'' if the argument returned ''false'' at last invocation and
+ * ''true'' otherwise.
*/
- public new abstract void foreach (ForallFunc<G> f);
+ public new abstract bool foreach (ForallFunc<G> f);
/**
* Stream function is an abstract function allowing writing many
*/
public virtual A fold<A> (FoldFunc<A, G> f, owned A seed)
{
- this.foreach ((item) => {seed = f ((owned) item, (owned) seed);});
+ this.foreach ((item) => {seed = f ((owned) item, (owned) seed); return true; });
return (owned) seed;
}
return current.key;
}
- public void foreach (ForallFunc<K> f) {
+ public bool foreach (ForallFunc<K> f) {
if (current != null) {
- f (current.key);
+ if (!f (current.key)) {
+ return false;
+ }
current = current.next;
} else if (_next == null) {
current = _map.first;
_prev = null;
}
}
- for (; current != null; current = current.next)
- f (current.key);
+ for (; current != null; current = current.next) {
+ if (!f (current.key)) {
+ return false;
+ }
+ }
+ return true;
}
}
return iterator.current.key;
}
- public void foreach (ForallFunc<K> f) {
- if (valid)
- f (iterator.current.key);
- while (iterator.next ())
- f (iterator.current.key);
+ public bool foreach (ForallFunc<K> f) {
+ if (valid) {
+ if (!f (iterator.current.key)) {
+ return false;
+ }
+ }
+ while (iterator.next ()) {
+ if (!f (iterator.current.key)) {
+ return false;
+ }
+ }
+ return true;
}
}
return current.value;
}
- public void foreach (ForallFunc<V> f) {
+ public bool foreach (ForallFunc<V> f) {
if (current != null) {
- f (current.key);
+ if (!f (current.key)) {
+ return false;
+ }
current = current.next;
} else if (_next == null) {
current = _map.first;
_prev = null;
}
}
- for (; current != null; current = current.next)
- f (current.key);
+ for (; current != null; current = current.next) {
+ if (!f (current.key)) {
+ return false;
+ }
+ }
+ return true;
}
}
return iterator.current.value;
}
- public void foreach (ForallFunc<V> f) {
- if (valid)
- f (iterator.current.key);
- while (iterator.next ())
- f (iterator.current.key);
+ public bool foreach (ForallFunc<V> f) {
+ if (valid) {
+ if (!f (iterator.current.key)) {
+ return false;
+ }
+ }
+ while (iterator.next ()) {
+ if (!f (iterator.current.key)) {
+ return false;
+ }
+ }
+ return true;
}
}
unset ();
}
- public void foreach (ForallFunc<Map.Entry<K, V>> f) {
+ public bool foreach (ForallFunc<Map.Entry<K, V>> f) {
if (current != null) {
- f (Entry.entry_for<K,V> (current));
+ if (!f (Entry.entry_for<K,V> (current))) {
+ return false;
+ }
current = current.next;
} else if (_next == null) {
current = _map.first;
_prev = null;
}
}
- for (; current != null; current = current.next)
- f (Entry.entry_for<K,V> (current));
+ for (; current != null; current = current.next) {
+ if (!f (Entry.entry_for<K,V> (current))) {
+ return false;
+ }
+ }
+ return true;
}
}
unset ();
}
- public void foreach (ForallFunc<Map.Entry<K, V>> f) {
- if (valid)
- f (Entry.entry_for<K,V> (iterator.current));
- while (iterator.next ())
- f (Entry.entry_for<K,V> (iterator.current));
+ public bool foreach (ForallFunc<Map.Entry<K, V>> f) {
+ if (valid) {
+ if (!f (Entry.entry_for<K,V> (iterator.current))) {
+ return false;
+ }
+ }
+ while (iterator.next ()) {
+ if (!f (Entry.entry_for<K,V> (iterator.current))) {
+ return false;
+ }
+ }
+ return true;
}
}
}
}
- public void foreach (ForallFunc<G> f) {
+ public bool foreach (ForallFunc<G> f) {
assert (stamp == _set.stamp);
if (current != null) {
- f (current.key);
+ if (!f (current.key)) {
+ return false;
+ }
_next = current.next;
} else if (!started) {
_next = _set._first;
}
while (_next != null) {
current = _next;
- f (current.key);
+ if (!f (current.key)) {
+ return false;
+ }
_next = current.next;
}
+ return true;
}
private weak Node<G>? current = null;
}
}
- public void foreach(ForallFunc<G> f) {
- if(valid)
- f(get());
- while(next())
- f(get());
+ public bool foreach(ForallFunc<G> f) {
+ if(valid) {
+ if (!f(get())) {
+ return false;
+ }
+ }
+ while(next()) {
+ if (!f(get())) {
+ return false;
+ }
+ }
+ return true;
}
private new TreeSet<G> set;
public bool valid { get { return _current != null; } }
public bool read_only { get { return true; } }
- public void foreach (ForallFunc<G> f) {
+ public bool foreach (ForallFunc<G> f) {
if (_current != null) {
- f (_current);
+ if (!f (_current)) {
+ return false;
+ }
}
if (_next != null) {
_current = (owned)_next;
- f (_current);
+ if (!f (_current)) {
+ return false;
+ }
} else if (_end) {
- return;
+ return true;
}
if (_current == null) {
_current = _func ();
if (_current == null) {
_end = true;
- return;
+ return true;
} else {
- f (_current);
+ if (!f (_current)) {
+ return false;
+ }
}
}
while ((_next = _func ()) != null) {
_current = (owned)_next;
- f (_current);
+ if (!f (_current)) {
+ return false;
+ }
}
_end = true;
+ return true;
}
private UnfoldFunc<G> _func;
int count = 0;
- test_collection.iterator ().foreach ((x) => {count++;});
+ test_collection.iterator ().foreach ((x) => {count++; return true;});
assert (count == 3);
Iterator<string> iter = test_collection.iterator ();
assert (iter.next ());
- iter.foreach ((x) => {count++;});
+ iter.foreach ((x) => {count++; return true;});
assert (count == 6);
}
int count = 0;
- test_map.map_iterator ().foreach ((x, y) => {count++;});
+ test_map.map_iterator ().foreach ((x, y) => {count++; return true;});
assert (count == 3);
var iter = test_map.map_iterator ();
assert (iter.next ());
- iter.foreach ((x, y) => {count++;});
+ iter.foreach ((x, y) => {count++; return true;});
assert (count == 6);
}