aboutsummaryrefslogtreecommitdiff
path: root/src/eval
diff options
context:
space:
mode:
Diffstat (limited to 'src/eval')
-rw-r--r--src/eval/index.ts23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/eval/index.ts b/src/eval/index.ts
index e88b583..f80c04d 100644
--- a/src/eval/index.ts
+++ b/src/eval/index.ts
@@ -3,21 +3,22 @@ import { Expr, ListExpr } from '../types'
import {match} from '../utils';
export const find = <T>([startO, exprs, endO]: ListExpr, list: T[]): any => {
- const check = (e: Expr) => <T>(x: T, _i: number, _l: T[]): boolean => {
+ const check = (expr: Expr) => <T>(x: T, i: number, ls: 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,
+ expr,
+ match<boolean, Expr>({
+ AnyItem: _ => true,
+ AnyNumber: _ => typeof x === 'number',
+ AnyString: _ => typeof x === 'string',
+ AnyBool: _ => typeof x === 'boolean',
+ Truthy: _ => !!x,
+ Falsey: _ => !x,
+ Group: ({ exprs }) => exprs.every(e => check(e)(x, i, ls)),
+ _: _ => false,
})
)
};
-
+
const cs = exprs.map(check)
return list.filter((x, i, ls) => cs.every(c => c(x, i, ls)))