Generators

Brian Goetz brian.goetz at oracle.com
Thu Jan 3 13:00:34 PST 2013


> To be clear: range and ints() are the only remaining int generators?

Ranges: there's a "stepping" version of range too.  And there will be 
long equivalents.

Repeating: there will be int versions of iterate/generate.

BigIntegers: This already works:
   Stream<BigInteger> range = iterate(new BI(0), bi -> bi.plus(1))

but we could add something to BigInteger too.

>
> There should be an iterator for stepping functions and infinite streams
> of 1's etc.
>
> ints() is nice anyway for samples and demos.  I can't complain too much.
>   Though the iterator form is pretty simple.  I think ints() should
> wrap, just like the simple iterator implementation.
>
> Will the T generators allow us to generate streams of BigInteger?  Those
> are useful for samples and demos.  Generate a gazillion Fibonacci numbers.
>
>
> On Thu, Jan 3, 2013 at 12:50 PM, Brian Goetz <brian.goetz at oracle.com
> <mailto:brian.goetz at oracle.com>> wrote:
>
>     Things like
>
>     int sumOfFirstHundredPrimes =
>        ints().filter(isPrime()).__limit(100).sum();
>
>     where you don't know how many input elements you'll have to examine.
>
>
>
>     On 1/3/2013 3:44 PM, Sam Pullara wrote:
>
>         These look pretty reasonable to me. What is the motivation for
>         ints()?
>
>         Sam
>
>         On Thu, Jan 3, 2013 at 11:49 AM, Brian Goetz
>         <brian.goetz at oracle.com <mailto:brian.goetz at oracle.com>
>         <mailto:brian.goetz at oracle.com
>         <mailto:brian.goetz at oracle.com>__>> wrote:
>
>              I'm looking over our generators.  Currently we have:
>
>                 repeat(T)
>                 repeat(n, T)
>                 repeatedly(Supplier<T>)
>                 repeatedly(n, Supplier<T>)
>                 iterate(T, UnaryOperator<T>)
>                 cycle(Iterable)
>
>              I'd like to pare this down a lot.  Paul and I have been
>         discussing
>              techniques for making limit() more efficient, at which
>         point the
>              first four can collapse to
>
>                 generate(Supplier<T>)
>
>              since you can simulate repeat(T) with generate(() -> T) and the
>              limited versions with generate().limit().
>
>              That leaves us with
>
>                 iterate(T, UnaryOperator<T>)
>                 cycle(Iterable)
>
>              and I'm thinking cycle doesn't pull its weight either.  If
>         we took
>              that out, we'd be down to the pleasantly small set of:
>
>                 generate(Supplier<T>)
>                 iterate(T, UnaryOperator<T>)
>
>              For integer generators, we have
>
>                 range(from, to)
>
>              and I think we should add
>
>                 ints() -> sugar for range(0, MAX_INT)
>
>              (Or should ints() be truly infinite, wrapping around?)
>
>
>


More information about the lambda-libs-spec-experts mailing list