Stream: ideas

Topic: roc-parser record builder


view this post on Zulip Luke Boswell (Oct 16 2024 at 09:11):

I was looking at https://github.com/lukewilliamboswell/roc-parser again today for something and had a thought... should we revisit this API now that we have Record Builders?

view this post on Zulip Sam Mohr (Oct 16 2024 at 13:05):

To be fair, map and map2 are already defined for Parser in Core, so you can do everything you should need with those. Though we discovered the value of a static record builder field with roc-random, but you also have const in Core.

view this post on Zulip Sam Mohr (Oct 16 2024 at 13:10):

The difference is that we should maybe name Core something more descriptive for default imports (Core.map2 -> Parser.map2), and consider aliasing map2 to something like chain or sequence or stringTogether.

view this post on Zulip Sam Mohr (Oct 16 2024 at 13:14):

Which means we can have:

dateParser =
    { Parser.chain <-
        day: Parser.u64,
        month: monthParser,
        year: Parser.u64,
    }

date = dateStr
    |> try Parser.parse dateParser

view this post on Zulip Sam Mohr (Oct 16 2024 at 13:16):

Yeah, looking at Core.parse, we should probably go through and rename all parsing functions in Core so that they make sense with a Parser prefix instead.

view this post on Zulip Sam Mohr (Oct 16 2024 at 13:16):

Something like Parser.apply and Parser.applyPartial

view this post on Zulip Agus Zubiaga (Oct 16 2024 at 15:35):

I'd suggest combine or build instead of chain. To me, chain sounds like andThen/bind.

view this post on Zulip Richard Feldman (Oct 16 2024 at 15:36):

or batch maybe?

view this post on Zulip Agus Zubiaga (Oct 16 2024 at 15:37):

yeah, I like that one too


Last updated: Jun 16 2026 at 16:19 UTC