Skip to content

Commit 8f46c4e

Browse files
authored
Merge pull request #10 from mkantor/simplify-readme-example
Simplify README example
2 parents 74c9ce0 + 3528312 commit 8f46c4e

File tree

2 files changed

+2
-16
lines changed

2 files changed

+2
-16
lines changed

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,5 @@ const compoundExpression = map(
4949

5050
const expression: Parser<number> = oneOf([compoundExpression, number])
5151

52-
const evaluate = (input: string) =>
53-
either.flatMap(expression(input), ({ remainingInput, output }) =>
54-
remainingInput.length !== 0
55-
? either.makeLeft('excess content followed valid input')
56-
: either.makeRight(output),
57-
)
58-
59-
console.log(evaluate('2+2-1').value) // logs "3"
52+
console.log(parse(expression, '2+2-1').value) // logs "3"
6053
```

src/parsing.test.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,7 @@ test('README example', _ => {
200200

201201
const expression: Parser<number> = oneOf([compoundExpression, number])
202202

203-
const evaluate = (input: string) =>
204-
either.flatMap(expression(input), ({ remainingInput, output }) =>
205-
remainingInput.length !== 0
206-
? either.makeLeft('excess content followed valid input')
207-
: either.makeRight(output),
208-
)
209-
210-
assertRight(evaluate('2+2-1'), 3)
203+
assertRight(parse(expression, '2+2-1'), 3)
211204
})
212205

213206
const longInputLength = 10000

0 commit comments

Comments
 (0)