/** * Creates a {@link Flow} from a {@linkplain LazyFunction lazy function}. */ public static <T> Flow<T> lazy(LazyFunction<T> function) { assert function != null; return new LazyFlow<T>(function); }
@Override public synchronized boolean isEmpty() { resolve(); return empty; }
@Override public synchronized boolean isEmpty() { resolve(); return empty; }
/** * Creates a {@link Flow} from a {@linkplain LazyFunction lazy function}. */ public static <T> Flow<T> lazy(LazyFunction<T> function) { assert function != null; return new LazyFlow<T>(function); }
@Override public synchronized Flow<T> rest() { resolve(); return rest; }
private synchronized void resolve() { if (lazyFunction == null) return; LazyContinuation<T> continuation = lazyFunction.next(); if (continuation == null) { empty = true; rest = F.emptyFlow(); } else { lazyFirst = continuation.nextValue(); rest = new LazyFlow<T>(continuation.nextFunction()); } lazyFunction = null; } }
@Override public synchronized Flow<T> rest() { resolve(); return rest; }
private synchronized void resolve() { if (lazyFunction == null) return; LazyContinuation<T> continuation = lazyFunction.next(); if (continuation == null) { empty = true; rest = F.emptyFlow(); } else { lazyFirst = continuation.nextValue(); rest = new LazyFlow<T>(continuation.nextFunction()); } lazyFunction = null; } }
@Override public synchronized T first() { resolve(); // Immediately after resolving, all we have is the function to call to get // the first object. And once we get that object, we don't need (or want) the // function. if (lazyFirst != null) { first = lazyFirst.get(); lazyFirst = null; } return first; }
@Override public synchronized T first() { resolve(); // Immediately after resolving, all we have is the function to call to get // the first object. And once we get that object, we don't need (or want) the // function. if (lazyFirst != null) { first = lazyFirst.get(); lazyFirst = null; } return first; }