From aa006086f69c827d780e6e0e69947ca7ee6e2c70 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sat, 8 Jan 2022 22:27:01 +0530 Subject: feat: adds exposed filter function --- src/index.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/index.ts') 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 = (listExp: string | RegExp, list: T[]): T[] => + pipe( + listExp, + toSourceString, + parser, + map(([lxp, _]) => find(lxp, list)), + fold(([err, _]) => { + throw new Error(err) + }, identity), + ) -- cgit v1.3.1