diff options
author | Tomasz Chojnacki <tomaszchojnacki2001@gmail.com> | 2023-02-01 22:37:01 +0100 |
---|---|---|
committer | Tomasz Chojnacki <tomaszchojnacki2001@gmail.com> | 2023-02-01 22:37:01 +0100 |
commit | 8240608524987b3df864a34fdae9cfc0352c9477 (patch) | |
tree | 609015a5dedaa4197cfb877bd6074f62bfa78133 /aoc-2020-gleam/src/days | |
parent | 523fb053827b60bdcb4023e19509aec94f27dbfb (diff) | |
download | gleam_aoc2020-8240608524987b3df864a34fdae9cfc0352c9477.tar.gz gleam_aoc2020-8240608524987b3df864a34fdae9cfc0352c9477.zip |
Refactor parsers to use more idiomatic code
Diffstat (limited to 'aoc-2020-gleam/src/days')
-rw-r--r-- | aoc-2020-gleam/src/days/day02.gleam | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/aoc-2020-gleam/src/days/day02.gleam b/aoc-2020-gleam/src/days/day02.gleam index a56e0e1..6cfb294 100644 --- a/aoc-2020-gleam/src/days/day02.gleam +++ b/aoc-2020-gleam/src/days/day02.gleam @@ -37,12 +37,12 @@ fn is_line_valid2(line: Line) -> Bool { fn parse_policy() -> p.Parser(Policy) { p.int() - |> p.then_skip(p.grapheme("-")) - |> p.and_then(p.int()) - |> p.then_skip(p.grapheme(" ")) - |> p.and_then(p.any_grapheme()) - |> p.then_skip(p.grapheme(":")) - |> p.then_skip(p.grapheme(" ")) + |> p.then_skip(p.grapheme_literal("-")) + |> p.then(p.int()) + |> p.then_skip(p.grapheme_literal(" ")) + |> p.then(p.any_grapheme()) + |> p.then_skip(p.grapheme_literal(":")) + |> p.then_skip(p.grapheme_literal(" ")) |> p.map(with: fn(x) { let #(#(min, max), grapheme) = x Policy(min, max, grapheme) @@ -52,10 +52,10 @@ fn parse_policy() -> p.Parser(Policy) { fn parse_line(string: String) -> Line { let line_parser = parse_policy() - |> p.and_then(p.all_remaining()) + |> p.then(p.any_string()) |> p.map(fn(t) { Line(pair.first(t), pair.second(t)) }) - assert Ok(#(policy, _)) = p.run(line_parser, on: string) + assert Ok(policy) = p.parse_entire(string, with: line_parser) policy } |