Skip to content

Commit 7c2cb56

Browse files
committed
slight simplification of Parser
1 parent eb5da83 commit 7c2cb56

File tree

1 file changed

+5
-14
lines changed
  • dot-parse/src/main/java/com/google/common/labs/parse

1 file changed

+5
-14
lines changed

dot-parse/src/main/java/com/google/common/labs/parse/Parser.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,9 @@ public static Parser<Integer> codePoint() {
272272
*/
273273
public static <A, B, C> Parser<C> sequence(
274274
Parser<A> left, Parser<B> right, BiFunction<? super A, ? super B, ? extends C> combiner) {
275-
requireNonNull(left);
276275
requireNonNull(right);
277276
requireNonNull(combiner);
278-
return left.flatMap(
279-
leftValue -> right.map(rightValue -> combiner.apply(leftValue, rightValue)));
277+
return left.flatMap(v1 -> right.map(v2 -> combiner.apply(v1, v2)));
280278
}
281279

282280
/**
@@ -285,9 +283,7 @@ public static <A, B, C> Parser<C> sequence(
285283
* default value is passed to the {@code combiner} function.
286284
*/
287285
public static <A, B, C> Parser<C> sequence(
288-
Parser<A> left,
289-
Parser<B>.OrEmpty right,
290-
BiFunction<? super A, ? super B, ? extends C> combiner) {
286+
Parser<A> left, Parser<B>.OrEmpty right, BiFunction<? super A, ? super B, ? extends C> combiner) {
291287
return sequence(left, right.asUnsafeZeroWidthParser(), combiner);
292288
}
293289

@@ -297,9 +293,7 @@ public static <A, B, C> Parser<C> sequence(
297293
* corresponding default value is passed to the {@code combiner} function.
298294
*/
299295
public static <A, B, C> Parser<C>.OrEmpty sequence(
300-
Parser<A>.OrEmpty left,
301-
Parser<B>.OrEmpty right,
302-
BiFunction<? super A, ? super B, ? extends C> combiner) {
296+
Parser<A>.OrEmpty left, Parser<B>.OrEmpty right, BiFunction<? super A, ? super B, ? extends C> combiner) {
303297
return anyOf(
304298
sequence(left.notEmpty(), right, combiner),
305299
right.notEmpty().map(v2 -> combiner.apply(left.computeDefaultValue(), v2)))
@@ -312,15 +306,12 @@ public static <A, B, C> Parser<C>.OrEmpty sequence(
312306
* default value is passed to the {@code combiner} function.
313307
*/
314308
static <A, B, C> Parser<C> sequence(
315-
Parser<A>.OrEmpty left,
316-
Parser<B> right,
317-
BiFunction<? super A, ? super B, ? extends C> combiner) {
309+
Parser<A>.OrEmpty left, Parser<B> right, BiFunction<? super A, ? super B, ? extends C> combiner) {
318310
return sequence(left.asUnsafeZeroWidthParser(), right, combiner);
319311
}
320312

321313
/** Matches if any of the given {@code parsers} match. */
322-
@SafeVarargs
323-
public static <T> Parser<T> anyOf(Parser<? extends T>... parsers) {
314+
@SafeVarargs public static <T> Parser<T> anyOf(Parser<? extends T>... parsers) {
324315
return stream(parsers).collect(or());
325316
}
326317

0 commit comments

Comments
 (0)