Function mapChompedString

  • This works just like getChompedString but gives a bit more flexibility. For example, maybe you want to parse Elm doc comments and get (1) the full comment and (2) all of the names listed in the docs.

    Example

    Example Implementation

    You could implement mapChompedString like this:

        const mapChompedString =
    <A, B>(fn: (s: string, v: A) => B) =>
    (parser: P.Parser<A>): P.Parser<B> => {
    return P.succeed(
    (start: number) => (value: A) => (end: number) => (src: string) =>
    fn(src.slice(start, end), value)
    )
    .apply(P.getOffset)
    .apply(parser)
    .apply(P.getOffset)
    .apply(P.getSource);
    };

    Type Parameters

    • A

    • B

    Parameters

    • fn: ((s: string, v: A) => B)
        • (s: string, v: A): B
        • Parameters

          • s: string
          • v: A

          Returns B

    Returns ((parser: Simple.Parser<A>) => Simple.Parser<B>)