From f57452ece2db1521bc473cc212fce0661c428b7d Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Sat, 8 Nov 2025 08:14:46 -0800 Subject: [PATCH] list.reject --- src/prelude/list.ts | 7 +++++++ src/prelude/tests/prelude.test.ts | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/src/prelude/list.ts b/src/prelude/list.ts index 1f0ec76..8e861b9 100644 --- a/src/prelude/list.ts +++ b/src/prelude/list.ts @@ -14,6 +14,13 @@ export const list = { } return acc }, + reject: async (list: any[], cb: Function) => { + let acc: any[] = [] + for (const value of list) { + if (!(await cb(value))) acc.push(value) + } + return acc + }, reduce: async (list: any[], cb: Function, initial: any) => { let acc = initial for (const value of list) acc = await cb(acc, value) diff --git a/src/prelude/tests/prelude.test.ts b/src/prelude/tests/prelude.test.ts index 04ceb8b..069b174 100644 --- a/src/prelude/tests/prelude.test.ts +++ b/src/prelude/tests/prelude.test.ts @@ -193,6 +193,15 @@ describe('collections', () => { `).toEvaluateTo([3, 4, 5]) }) + test('list.reject doesnt keep matching elements', async () => { + await expect(` + is-even = do x: + (x % 2) == 0 + end + list.reject [1 2 3 4 5] is-even + `).toEvaluateTo([1, 3, 5]) + }) + test('list.reduce accumulates values', async () => { await expect(` add = do acc x: