Skip to content

Commit

Permalink
🎨 implement concat using map
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelvalley committed Jul 19, 2024
1 parent 3eaf642 commit bcbd571
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
13 changes: 1 addition & 12 deletions src/parz/combinators.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,8 @@ pub fn many(parser: Parser(a)) {
}
}

pub fn concat(parser: Parser(List(a)), merge) {
fn(input) {
case parser(input) {
Error(err) -> Error(err)
Ok(ok) -> {
Ok(ParserState(merge(ok.matched), ok.remaining))
}
}
}
}

pub fn concat_str(parser) {
concat(parser, string.concat)
map(parser, string.concat)
}

pub fn label_error(parser, message) {
Expand Down
6 changes: 3 additions & 3 deletions test/combinators_test.gleam
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import gleeunit/should
import parz.{run}
import parz/combinators.{
between, choice, concat, concat_str, label_error, left, many, many1, map,
maybe, right, sequence,
between, choice, concat_str, label_error, left, many, many1, map, maybe, right,
sequence,
}
import parz/parsers.{letters, str}
import parz/types.{ParserState}
Expand Down Expand Up @@ -132,7 +132,7 @@ pub fn sequence_test() {
|> should.be_error
}

pub fn concat_test() {
pub fn concat_str_test() {
let parser = concat_str(sequence([str("["), letters(), str("]")]))

run(parser, "[hello]")
Expand Down

0 comments on commit bcbd571

Please sign in to comment.