diff options
| author | Akshay Nair <phenax5@gmail.com> | 2022-01-10 21:29:42 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2022-01-10 21:29:42 +0530 |
| commit | 3581e398a2fe2f38bee7e6d13cbf609221f61672 (patch) | |
| tree | 95715115303ecb9620cbf37530e89a37c0ff5c4b /src/index.ts | |
| parent | aa006086f69c827d780e6e0e69947ca7ee6e2c70 (diff) | |
| download | elxr-3581e398a2fe2f38bee7e6d13cbf609221f61672.tar.gz elxr-3581e398a2fe2f38bee7e6d13cbf609221f61672.zip | |
feat: adds matchAll function (incomplete)
Diffstat (limited to 'src/index.ts')
| -rw-r--r-- | src/index.ts | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/index.ts b/src/index.ts index 691d676..db6630c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,17 +1,29 @@ -import { fold, map } from 'fp-ts/lib/Either' -import { identity, pipe } from 'fp-ts/lib/function' -import { find } from './eval' +import { getOrElseW, map } from 'fp-ts/lib/Either' +import { flow, pipe } from 'fp-ts/lib/function' +import {fst} from 'fp-ts/lib/Tuple' +import * as ev from './eval' import { parser } from './parser' +import {ListExpr} from './types' const toSourceString = (r: string | RegExp): string => typeof r === 'string' ? r : r.source -export const filter = <T>(listExp: string | RegExp, list: T[]): T[] => +export const liexp: (r: string | RegExp) => ListExpr = flow( + toSourceString, + parser, + map(fst), + getOrElseW(([e, _]) => { throw new Error(e) }) +) + +export const matchAll = <T>(exp: string | RegExp, list: T[]) => + pipe( + exp, + liexp, + lxp => ev.matchAll(lxp, list), + ) + +export const filter = <T>(exp: string | RegExp, list: T[]): T[] => pipe( - listExp, - toSourceString, - parser, - map(([lxp, _]) => find(lxp, list)), - fold(([err, _]) => { - throw new Error(err) - }, identity), + exp, + liexp, + lxp => ev.find(lxp, list), ) |
