Exemplo n.º 1
0
 /**
  * Returns a parser that produces an element from the stream that satisfies the given predicate,
  * or fails.
  *
  * @param missing The error if no element is available.
  * @param sat The error if the element does not satisfy the predicate.
  * @param f The predicate that the element should satisfy.
  * @return A parser that produces an element from the stream that satisfies the given predicate,
  *     or fails.
  */
 public static <I, E> Parser<Stream<I>, I, E> satisfy(
     final F0<E> missing, final F<I, E> sat, final F<I, Boolean> f) {
   return StreamParser.<I, E>element(missing)
       .bind(
           x ->
               f.f(x)
                   ? Parser.<Stream<I>, I, E>value(x)
                   : Parser.<Stream<I>, I, E>fail(sat.f(x)));
 }