Skip to content

Commit bcbd571

Browse files
committed
🎨 implement concat using map
1 parent 3eaf642 commit bcbd571

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

src/parz/combinators.gleam

+1-12
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,8 @@ pub fn many(parser: Parser(a)) {
122122
}
123123
}
124124

125-
pub fn concat(parser: Parser(List(a)), merge) {
126-
fn(input) {
127-
case parser(input) {
128-
Error(err) -> Error(err)
129-
Ok(ok) -> {
130-
Ok(ParserState(merge(ok.matched), ok.remaining))
131-
}
132-
}
133-
}
134-
}
135-
136125
pub fn concat_str(parser) {
137-
concat(parser, string.concat)
126+
map(parser, string.concat)
138127
}
139128

140129
pub fn label_error(parser, message) {

test/combinators_test.gleam

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import gleeunit/should
22
import parz.{run}
33
import parz/combinators.{
4-
between, choice, concat, concat_str, label_error, left, many, many1, map,
5-
maybe, right, sequence,
4+
between, choice, concat_str, label_error, left, many, many1, map, maybe, right,
5+
sequence,
66
}
77
import parz/parsers.{letters, str}
88
import parz/types.{ParserState}
@@ -132,7 +132,7 @@ pub fn sequence_test() {
132132
|> should.be_error
133133
}
134134

135-
pub fn concat_test() {
135+
pub fn concat_str_test() {
136136
let parser = concat_str(sequence([str("["), letters(), str("]")]))
137137

138138
run(parser, "[hello]")

0 commit comments

Comments
 (0)