de.cm.frw.core.fun.impl
Class Stream
java.lang.Object
de.cm.frw.core.fun.impl.Stream
- All Implemented Interfaces:
- java.lang.Iterable, java.util.Iterator
- Direct Known Subclasses:
- Stream.Filtered, Stream.Lazy, Stream.Range
public abstract class Stream
- extends java.lang.Object
- implements java.lang.Iterable, java.util.Iterator
Stream class implements Iterator and supports lazy evaluation
insofar as next() may be implemented to calculate the next element
on demand.
Memoization (or caching) will be implemented here, too. Constructor parameter
will allow for turning memoization on or of.
The Iterator.remove() method is implemented to have no effect, but may be redefined
in derived classes. Maybe should have an implementation if memoization is active,
to remove the result pointed at, from memoized results ... not clear if useful ...
- Author:
- cm
Nested Class Summary |
static class |
Stream.Filtered
|
static class |
Stream.Lazy
|
static class |
Stream.Range
|
static class |
Stream.SimplePair
This would be called an cons cell in Lisp:
(cons a b) = new Pair(a, b)
(car (cons a b)) = a = (new Pair(a, b)).first()
(cdr (cons a b)) = b = (new Pair(a, b)).second() |
Method Summary |
static Stream |
filter(Predicate p,
Stream s)
Takes a predicate p and a stream s and returns a filtered stream, i.e. |
java.util.Iterator |
iterator()
|
static void |
main(java.lang.String[] args)
|
abstract java.lang.Object |
next()
|
void |
remove()
|
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.Iterator |
hasNext |
Stream
public Stream()
filter
public static Stream filter(Predicate p,
Stream s)
- Takes a predicate p and a stream s and returns a filtered stream, i.e.
a stream of the elements in s, where p is true.
Short for
new Stream.Filtered(p, s);
- Parameters:
p
- the predicate for filterings
- the stream
- Returns:
- a new instance of the class
Stream.Filtered
using p and s
main
public static void main(java.lang.String[] args)
- Parameters:
args
-
iterator
public java.util.Iterator iterator()
- Specified by:
iterator
in interface java.lang.Iterable
next
public abstract java.lang.Object next()
- Specified by:
next
in interface java.util.Iterator
remove
public void remove()
- Specified by:
remove
in interface java.util.Iterator