Skip to content

Commit

Permalink
Update StreamMapToOptionalGet Javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed Aug 18, 2022
1 parent 7883b31 commit 451643c
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,16 @@ Stream<T> after(Stream<Optional<T>> stream) {
}
}

/** Within a stream's map operation unconditional {@link Optional#get()} calls can be avoided. */
// XXX: An alternative approach is to `.flatMap(Optional::stream)`. That may be a bit longer, but
// yield nicer code. Think about it.
/**
* Within a stream's map operation unconditional {@link Optional#orElseThrow()} calls can be
* avoided.
*
* <p><strong>Warning:</strong> this rewrite rule is not completely behavior preserving. The
* original code throws an exception if no value is present, while the replacement will silently
* continue.
*/
// XXX: An alternative approach is to use `.flatMap(Optional::stream)`. That may be a bit longer,
// but yields nicer code. Think about it.
abstract static class StreamMapToOptionalGet<T, S> {
@Placeholder
abstract Optional<S> toOptionalFunction(@MayOptionallyUse T element);
Expand Down

0 comments on commit 451643c

Please sign in to comment.