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'
22import * as either from '@matt.kantor/either'
33import { nothing } from './constructors.js'
44import 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.
Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ import {
1111 oneOf ,
1212 oneOrMore ,
1313 sequence ,
14- transformOutput ,
1514 zeroOrMore ,
1615} from './combinators.js'
1716import {
@@ -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' ] )
You can’t perform that action at this time.
0 commit comments