From d19a1e4e02c6743f057d03caa9337a5b47bfa9cd Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sat, 8 Jan 2022 18:37:57 +0530 Subject: feat(eval): implements basic eval filtering --- src/eval/index.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/eval/index.ts (limited to 'src/eval') diff --git a/src/eval/index.ts b/src/eval/index.ts new file mode 100644 index 0000000..e88b583 --- /dev/null +++ b/src/eval/index.ts @@ -0,0 +1,24 @@ +import {pipe} from 'fp-ts/function'; +import { Expr, ListExpr } from '../types' +import {match} from '../utils'; + +export const find = ([startO, exprs, endO]: ListExpr, list: T[]): any => { + const check = (e: Expr) => (x: T, _i: number, _l: T[]): boolean => { + return pipe( + e.tag as any, + match({ + AnyItem: () => true, + AnyNumber: () => typeof x === 'number', + AnyString: () => typeof x === 'string', + AnyBool: () => typeof x === 'boolean', + Truthy: () => !!x, + Falsey: () => !x, + _: () => false, + }) + ) + }; + + const cs = exprs.map(check) + + return list.filter((x, i, ls) => cs.every(c => c(x, i, ls))) +} -- cgit v1.3.1