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 Implementation
You could implement mapChompedString like this:
mapChompedString
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); };
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: