Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement withFirst(): extract first stream element #50

Closed
5 tasks done
amaembo opened this issue Jan 11, 2016 · 0 comments
Closed
5 tasks done

Implement withFirst(): extract first stream element #50

amaembo opened this issue Jan 11, 2016 · 0 comments
Milestone

Comments

@amaembo
Copy link
Owner

amaembo commented Jan 11, 2016

Sometimes it's useful to extract the first stream element and use it to process other elements. Some solutions are proposed and discussed here. In StreamEx we must make such operation lazy: it should not consume any stream elements until the terminal operation is performed.

Two possible versions are proposed:

class StreamEx<T> {
    // Return EntryStream where keys are the same and represent the first stream element
    // while values are the rest elements (the stream length is one element less than 
    // the original stream)
    public EntryStream<T, T> withFirst() {...};

    // Return StreamEx which elements are the result of applying the mapper function 
    // to the first stream element and every other element
    <U> StreamEx<U> withFirst(BiFunction<T, T, U> mapper) { ... };
}

The biggest problem is the current flatMap bug: this code must produce 1, 2, 3, 4, 5

StreamEx.of(0, 2, 4).flatMap(x -> Stream.of(x, x + 1)).parallel()
              .withFirst().values().toList();
  • Implementation
  • Tests
  • JavaDoc
  • Changes
  • Cheatsheet

Issue #54 extracted from this one as it's substantially different.

amaembo added a commit that referenced this issue Jan 11, 2016
amaembo added a commit that referenced this issue Jan 12, 2016
amaembo added a commit that referenced this issue Jan 12, 2016
better parallelization is impossible for such interface); more tests
amaembo added a commit that referenced this issue Jan 13, 2016
when outer closed; support of null; javaDoc
@amaembo amaembo added this to the 0.5.3 milestone Jan 13, 2016
amaembo added a commit that referenced this issue Jan 14, 2016
amaembo added a commit that referenced this issue Jan 15, 2016
@amaembo amaembo closed this as completed Jan 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant