@@ -28,7 +28,7 @@ THE SOFTWARE.
2828
2929// deno-fmt-ignore-file
3030
31- import { IsResultTrue } from './result .ts'
31+ import { Match } from './match .ts'
3232import { type TTake , Take } from './take.ts'
3333
3434// ------------------------------------------------------------------
@@ -58,15 +58,10 @@ export type TMany<Allowed extends string[], Discard extends string[], Input exte
5858 : [ Result , Input ]
5959)
6060/** Takes characters from the Input until no-match. The Discard set is used to omit characters from the match */
61- export function Many < Allowed extends string [ ] , Discard extends string [ ] , Input extends string >
62- ( allowed : [ ...Allowed ] , discard : [ ...Discard ] , input : Input , result : string = '' ) :
63- TMany < Allowed , Discard , Input > {
64- const takeResult = Take ( allowed , input ) as [ string , string ]
65- return (
66- IsResultTrue ( takeResult )
67- ? IsDiscard ( discard , takeResult [ 0 ] )
68- ? Many ( allowed , discard , takeResult [ 1 ] , result )
69- : Many ( allowed , discard , takeResult [ 1 ] , `${ result } ${ takeResult [ 0 ] } ` )
70- : [ result , input ]
71- ) as never
61+ export function Many < Allowed extends string [ ] , Discard extends string [ ] , Input extends string > ( allowed : [ ...Allowed ] , discard : [ ...Discard ] , input : Input , result : string = '' ) : TMany < Allowed , Discard , Input > {
62+ return Match ( Take ( allowed , input ) , ( Char , Rest ) =>
63+ IsDiscard ( discard , Char )
64+ ? Many ( allowed , discard , Rest , result )
65+ : Many ( allowed , discard , Rest , `${ result } ${ Char } ` ) ,
66+ ( ) => [ result , input ] ) as never
7267}
0 commit comments