jOOQ / jOOL

jOOλ - The Missing Parts in Java 8 jOOλ improves the JDK libraries in areas where the Expert Group's focus was elsewhere. It adds tuple support, function support, and a lot of additional functionality around sequential Streams. The JDK 8's main efforts (default methods, lambdas, and the Stream API) were focused around maintaining backwards compatibility and implementing a functional API for parallelism.
http://www.jooq.org/products
Apache License 2.0
2.09k stars 168 forks source link

Seq.splitAt implementation is inefficient #308

Closed tlinkowski closed 7 years ago

tlinkowski commented 7 years ago

Iterating Seq.of(1, 2, 3, 4, 5, 6).splitAt(2).v1() requires consumption of entire Seq, and not only consumption of the first 2 elements (i.e. until given position is reached).

I propose the following implementation using SeqBuffer proposed in #305:

    static <T> Tuple2<Seq<T>, Seq<T>> splitAt(Stream<? extends T> stream, long position) {
        SeqBuffer<T> buffer = SeqBuffer.of(stream);
        return tuple(buffer.seq().limit(position), buffer.seq().skip(position));
    }
lukaseder commented 7 years ago

OK this depends on SeqBuffer. I'll look at that first: https://github.com/jOOQ/jOOL/issues/305

lukaseder commented 7 years ago

Hmm, I think you haven't sent a PR for these changes yet. Would you mind doing so, so you can get credit?

tlinkowski commented 7 years ago

Sure!

tlinkowski commented 7 years ago

Hm, I just realized that I implemented it inside [#305] (in the squashed commit 61e75370). Unfortunately, I forgot to add "[#308] more efficient Seq.splitAt implementation" to the commit message.

lukaseder commented 7 years ago

Oh yes indeed, thanks very much. The test also runs. I've activated it again.