Function many1

  • Similar to many, apply a parser repeatedly until it fails, but it requires at least one item to succeed.

    Example

       // This parser parses an int and then all of the spaces after it.
    const int = number({ int: (n) => n }).skip(spaces);
    // We then repeat that parser zero or more times.
    const ints: Parser<number[]> = many(int);

    ints.run("1 2 3")
    // => Ok([1, 2, 3])

    ints.run("")
    // => Err ...

    Remarks

    You can think of it like this:

      const many1 = (parseItem) =>
    many(parseItem).andThen((items) =>
    items.length === 0 ? problem("Need to succeed at least once!") : succeed(items)
    );

    Type Parameters

    • A

    Parameters

    Returns Simple.Parser<A[]>