diff options
author | Tomasz Chojnacki <tomaszchojnacki2001@gmail.com> | 2023-02-22 16:55:17 +0100 |
---|---|---|
committer | Tomasz Chojnacki <tomaszchojnacki2001@gmail.com> | 2023-02-22 16:55:17 +0100 |
commit | d49a86821f2abba0950b32780100ecdf27384789 (patch) | |
tree | 7677eebb7467b8be237c805d094751e1188e1651 /aoc-2020-gleam/src/util/parser.gleam | |
parent | efde7d6c018e360efbf590a67d128de41e6da7af (diff) | |
download | gleam_aoc2020-d49a86821f2abba0950b32780100ecdf27384789.tar.gz gleam_aoc2020-d49a86821f2abba0950b32780100ecdf27384789.zip |
Finish day 8
Diffstat (limited to 'aoc-2020-gleam/src/util/parser.gleam')
-rw-r--r-- | aoc-2020-gleam/src/util/parser.gleam | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/aoc-2020-gleam/src/util/parser.gleam b/aoc-2020-gleam/src/util/parser.gleam index d5fa429..1ca2447 100644 --- a/aoc-2020-gleam/src/util/parser.gleam +++ b/aoc-2020-gleam/src/util/parser.gleam @@ -140,9 +140,12 @@ pub fn skip_ws(after parser: Parser(a)) -> Parser(a) { |> skip(ws0()) } +pub fn replace(parser: Parser(a), with value: b) -> Parser(b) { + map(parser, with: fun.constant(value)) +} + pub fn ignore(parser: Parser(a)) -> Parser(Nil) { - parser - |> map(fun.constant(Nil)) + replace(parser, with: Nil) } pub fn then(first: Parser(a), second: Parser(b)) -> Parser(#(a, b)) { @@ -162,7 +165,7 @@ pub fn skip(first: Parser(a), second: Parser(b)) -> Parser(a) { |> map(with: pair.first) } -pub fn proceed(first: Parser(a), second: Parser(b)) -> Parser(b) { +pub fn proceed(first: Parser(a), with second: Parser(b)) -> Parser(b) { first |> then(second) |> map(with: pair.second) |