File tree Expand file tree Collapse file tree 2 files changed +1
-33
lines changed Expand file tree Collapse file tree 2 files changed +1
-33
lines changed Original file line number Diff line number Diff line change 1
- import type { Either , Right } from '@matt.kantor/either'
1
+ import type { Right } from '@matt.kantor/either'
2
2
import * as either from '@matt.kantor/either'
3
3
import { nothing } from './constructors.js'
4
4
import type {
5
- InvalidInputError ,
6
5
Parser ,
7
6
ParserResult ,
8
7
ParserWhichAlwaysSucceeds ,
@@ -187,21 +186,6 @@ type SequenceOutput<Parsers extends readonly Parser<unknown>[]> = {
187
186
[ Index in keyof Parsers ] : OutputOf < Parsers [ Index ] >
188
187
}
189
188
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
-
205
189
/**
206
190
* Repeatedly apply `parser` to the input as long as it keeps succeeding.
207
191
* Outputs are collected in an array.
Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ import {
11
11
oneOf ,
12
12
oneOrMore ,
13
13
sequence ,
14
- transformOutput ,
15
14
zeroOrMore ,
16
15
} from './combinators.js'
17
16
import {
@@ -131,21 +130,6 @@ suite('combinators', _ => {
131
130
assertFailure ( ab ( 'bab' ) )
132
131
} )
133
132
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
-
149
133
test ( 'zeroOrMore' , _ => {
150
134
const zeroOrMoreA = zeroOrMore ( literal ( 'a' ) )
151
135
assertSuccess ( zeroOrMoreA ( 'a' ) , [ 'a' ] )
You can’t perform that action at this time.
0 commit comments