Skip to content

Commit

Permalink
Improve StreamMapToOptionalGet Refaster template documentation (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie authored Aug 19, 2022
1 parent 9ab5bbe commit a58630b
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 the mapping operation does not produce a value, while the
* replacement does not.
*/
// 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 a58630b

Please sign in to comment.