diff options
| author | Akshay Nair <phenax5@gmail.com> | 2022-01-08 22:27:01 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2022-01-08 22:27:10 +0530 |
| commit | aa006086f69c827d780e6e0e69947ca7ee6e2c70 (patch) | |
| tree | 2330a10402d31d7a8d47e09de0ccd6c6d18764b8 /src/index.ts | |
| parent | 2b8ceabd93205f2f852aa08d5fcdc4a8151ae131 (diff) | |
| download | elxr-aa006086f69c827d780e6e0e69947ca7ee6e2c70.tar.gz elxr-aa006086f69c827d780e6e0e69947ca7ee6e2c70.zip | |
feat: adds exposed filter function
Diffstat (limited to '')
| -rw-r--r-- | src/index.ts | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/index.ts b/src/index.ts index 82eefe8..691d676 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,17 @@ +import { fold, map } from 'fp-ts/lib/Either' +import { identity, pipe } from 'fp-ts/lib/function' +import { find } from './eval' +import { parser } from './parser' -export * from './parser'; +const toSourceString = (r: string | RegExp): string => typeof r === 'string' ? r : r.source + +export const filter = <T>(listExp: string | RegExp, list: T[]): T[] => + pipe( + listExp, + toSourceString, + parser, + map(([lxp, _]) => find(lxp, list)), + fold(([err, _]) => { + throw new Error(err) + }, identity), + ) |
