3 * Copyright (C) 2011 Maciej Piechotka
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Maciej Piechotka <uzytkownik2@gmail.com>
23 internal class Gee.UnfoldIterator<G> : Object, Traversable<G>, Iterator<G> {
24 public UnfoldIterator (owned UnfoldFunc<G> func, owned Lazy<G>? current = null) {
25 _current = (owned)current;
34 _current = (owned)_next;
40 public bool has_next () {
52 assert (_current != null);
53 return _current.value;
56 public void remove () {
57 assert_not_reached ();
60 public bool valid { get { return _current != null; } }
61 public bool read_only { get { return true; } }
63 public bool foreach (ForallFunc<G> f) {
64 if (_current != null) {
65 if (!f (_current.value)) {
70 _current = (owned)_next;
71 if (!f (_current.value)) {
77 if (_current == null) {
79 if (_current == null) {
83 if (!f (_current.value)) {
88 while ((_next = _func ()) != null) {
89 _current = (owned)_next;
90 if (!f (_current.value)) {
98 private UnfoldFunc<G> _func;
99 private Lazy<G>? _current;
100 private Lazy<G>? _next;