aboutsummaryrefslogtreecommitdiff
path: root/aoc-2020-gleam/src/util
diff options
context:
space:
mode:
authorTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2023-03-02 21:40:59 +0100
committerTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2023-03-02 21:40:59 +0100
commit6c661db5b3e167d45554f7c5e4838dbc3bffa63a (patch)
tree6ba5eebddc1713f5bd4ee9fe740937a8031d151e /aoc-2020-gleam/src/util
parent2ba7501d516afa4ab240faccefb6a3f72223598e (diff)
downloadgleam_aoc2020-6c661db5b3e167d45554f7c5e4838dbc3bffa63a.tar.gz
gleam_aoc2020-6c661db5b3e167d45554f7c5e4838dbc3bffa63a.zip
Refactor using constructs from Gleam v0.27
Diffstat (limited to 'aoc-2020-gleam/src/util')
-rw-r--r--aoc-2020-gleam/src/util/parser.gleam14
1 files changed, 5 insertions, 9 deletions
diff --git a/aoc-2020-gleam/src/util/parser.gleam b/aoc-2020-gleam/src/util/parser.gleam
index 1ca2447..f143c92 100644
--- a/aoc-2020-gleam/src/util/parser.gleam
+++ b/aoc-2020-gleam/src/util/parser.gleam
@@ -150,10 +150,8 @@ pub fn ignore(parser: Parser(a)) -> Parser(Nil) {
pub fn then(first: Parser(a), second: Parser(b)) -> Parser(#(a, b)) {
create(fn(input) {
- use parsed1 <- res.then(run(first, on: input))
- let #(value1, remaining1) = parsed1
- use parsed2 <- res.then(run(second, on: remaining1))
- let #(value2, remaining2) = parsed2
+ use #(value1, remaining1) <- res.then(run(first, on: input))
+ use #(value2, remaining2) <- res.then(run(second, on: remaining1))
Ok(#(#(value1, value2), remaining2))
})
|> labeled(with: first.label <> " |> then(" <> second.label <> ")")
@@ -219,8 +217,7 @@ fn flat_map(
with mapper: fn(a) -> Result(b, ParseError),
) -> Parser(b) {
create(fn(input) {
- use parsed <- res.then(run(parser, on: input))
- let #(value, remaining) = parsed
+ use #(value, remaining) <- res.then(run(parser, on: input))
value
|> mapper
|> res.map(with: fn(new_value) { #(new_value, remaining) })
@@ -248,7 +245,7 @@ fn succeeding(with value: a) -> Parser(a) {
}
fn failing(with error: ParseError) -> Parser(a) {
- create(fn(_) { Error(error) })
+ create(fun.constant(Error(error)))
}
fn lift2(function: fn(a, b) -> c) -> fn(Parser(a), Parser(b)) -> Parser(c) {
@@ -308,8 +305,7 @@ pub fn str_of_many0(of parser: Parser(String)) -> Parser(String) {
pub fn many1(of parser: Parser(a)) -> Parser(List(a)) {
create(fn(input) {
- use parsed <- res.then(run(parser, on: input))
- let #(value, rest) = parsed
+ use #(value, rest) <- res.then(run(parser, on: input))
let #(previous, rest) = do_zero_or_more(rest, with: parser)
Ok(#([value, ..previous], rest))
})