package com.example.playground.monadic.parser.combinators;

import com.example.playground.result.Result;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.stream.BaseStream;

import static com.example.playground.monadic.parser.combinators.ParserResult.parserResult;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class Parsers {
    public static <T, E, I, S extends BaseStream<I, S>> Parser<T, E, I, S> result(T result) {
        return input -> Result.result(parserResult(result, input));
    }

    public static <T, E, I, S extends BaseStream<I, S>> Parser<T, E, I, S> error(E error) {
        return input -> Result.error(error);
    }
}

@@ -159,16 +159,70 @@
 uctor;%0A%0A
+import java.util.Iterator;%0Aimport java.util.Optional;%0A
 import j
@@ -249,16 +249,16 @@
 Stream;%0A
-
 %0Aimport 
@@ -340,16 +340,64 @@
 rResult;
+%0Aimport static java.util.stream.Stream.generate;
 %0A%0A@NoArg
@@ -725,24 +725,24 @@
 (E error) %7B%0A
-
         retu
@@ -779,11 +779,487 @@
 );%0A    %7D
+%0A%0A    public static %3CT, E, S extends BaseStream%3CT, S%3E%3E Parser%3CT, E, T, S%3E item(E error) %7B%0A        return input -%3E Optional.of(input.iterator())%0A                .filter(Iterator::hasNext)%0A                .map(i -%3E %7B%0A                    @SuppressWarnings(%22unchecked%22) final S stream = (S) generate(i::next);%0A                    return Result.%3CParserResult%3CT, T, S%3E, E%3Eresult(parserResult(i.next(), stream));%0A                %7D)%0A                .orElse(Result.error(error));%0A    %7D
 %0A%7D%0A

Add item parser