Example #1
0
 /**
  * Returns a parser that produces an element from the stream if it is available and fails
  * otherwise.
  *
  * @param e The error to fail with if no element is available.
  * @return A parser that produces an element from the stream if it is available and fails
  *     otherwise.
  */
 public static <I, E> Parser<Stream<I>, I, E> element(final F0<E> e) {
   return parser(
       is ->
           is.isEmpty()
               ? Validation.<E, Result<Stream<I>, I>>fail(e.f())
               : Validation.<E, Result<Stream<I>, I>>success(result(is.tail()._1(), is.head())));
 }
Example #2
0
 /**
  * Returns a parser that negates this parser. If this parser succeeds, then the returned parser
  * fails and vice versa.
  *
  * @param e The error message to fail with if this parser succeeds.
  * @return A parser that negates this parser.
  */
 public Parser<I, Unit, E> not(final F0<E> e) {
   return parser(
       i ->
           parse(i).isFail()
               ? Validation.<E, Result<I, Unit>>success(result(i, unit()))
               : Validation.<E, Result<I, Unit>>fail(e.f()));
 }