benjamin-hodgson / Pidgin

A lightweight and fast parsing library for C#.
https://www.benjamin.pizza/Pidgin/
MIT License
883 stars 68 forks source link

Is there a good way to turn Digit.Repeat(n) into a string? #137

Closed atrauzzi closed 1 year ago

atrauzzi commented 1 year ago

Right now it seems to return IEnumerable<char>, which is obviously a precursor to a string. I was wondering if Pidgin had any handy way of doing this, versus me just manually making the string in a Map somewhere later on?

benjamin-hodgson commented 1 year ago

Does this do what you meant?

static Parser<TToken, string> RepeatString<TToken>(this Parser<TToken, char> p, int n)
    => p.Repeat(n).Select(string.Concat);
atrauzzi commented 1 year ago

It's cleaner, yes :slightly_smiling_face: