Skip to content

Commit b0e5217

Browse files
authored
Merge pull request #5 from mkantor/nuke-transform-output-combinator
Remove `transformOutput` combinator
2 parents ae4f827 + 7efa7c7 commit b0e5217

File tree

2 files changed

+1
-33
lines changed

2 files changed

+1
-33
lines changed

src/combinators.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import type { Either, Right } from '@matt.kantor/either'
1+
import type { Right } from '@matt.kantor/either'
22
import * as either from '@matt.kantor/either'
33
import { nothing } from './constructors.js'
44
import type {
5-
InvalidInputError,
65
Parser,
76
ParserResult,
87
ParserWhichAlwaysSucceeds,
@@ -187,21 +186,6 @@ type SequenceOutput<Parsers extends readonly Parser<unknown>[]> = {
187186
[Index in keyof Parsers]: OutputOf<Parsers[Index]>
188187
}
189188

190-
/**
191-
* Refine/transform the output of `parser` via a function which may fail.
192-
*/
193-
export const transformOutput = <Output, NewOutput>(
194-
parser: Parser<Output>,
195-
f: (output: Output) => Either<InvalidInputError, NewOutput>,
196-
): Parser<NewOutput> => {
197-
const transformation = (success: Success<Output>) =>
198-
either.map(f(success.output), output => ({
199-
output,
200-
remainingInput: success.remainingInput,
201-
}))
202-
return input => either.flatMap(parser(input), transformation)
203-
}
204-
205189
/**
206190
* Repeatedly apply `parser` to the input as long as it keeps succeeding.
207191
* Outputs are collected in an array.

src/parsing.test.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
oneOf,
1212
oneOrMore,
1313
sequence,
14-
transformOutput,
1514
zeroOrMore,
1615
} from './combinators.js'
1716
import {
@@ -131,21 +130,6 @@ suite('combinators', _ => {
131130
assertFailure(ab('bab'))
132131
})
133132

134-
test('transformOutput', _ => {
135-
const aTransformedToUppercase = transformOutput(literal('a'), a =>
136-
either.makeRight(a.toUpperCase()),
137-
)
138-
assertSuccess(aTransformedToUppercase('a'), 'A')
139-
assertSuccess(aTransformedToUppercase('ab'), 'A')
140-
assertFailure(aTransformedToUppercase('b'))
141-
assertFailure(aTransformedToUppercase(''))
142-
assertFailure(
143-
transformOutput(anySingleCharacter, _ =>
144-
either.makeLeft({ kind: 'invalidInput', input: '', message: '' }),
145-
)(''),
146-
)
147-
})
148-
149133
test('zeroOrMore', _ => {
150134
const zeroOrMoreA = zeroOrMore(literal('a'))
151135
assertSuccess(zeroOrMoreA('a'), ['a'])

0 commit comments

Comments
 (0)