Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e09dd29
:construction: Add async chain idea
reckter Nov 26, 2024
969e58a
Add more test
reckter Nov 26, 2024
61b2c6a
Make AsyncChain eager, and not evaluate multiple times
reckter Nov 26, 2024
0731e19
Move async code to their own folder
reckter Jul 29, 2025
7b13fa6
Add more async chain test, move asynh chain back into one file
reckter Jul 29, 2025
f2c67f7
Add more types to objChain function
reckter Jul 30, 2025
80989d9
Simplify objChain types
reckter Aug 1, 2025
072923a
Fix tests and add a new one
reckter Aug 1, 2025
1456dd9
fix some functions
reckter Aug 1, 2025
bd87874
Do todos
reckter Aug 1, 2025
34a95c0
:camera_flash:
reckter Aug 1, 2025
918ae05
Update src/collections/AsyncChain.ts
reckter Aug 1, 2025
593c010
Update src/collections/AsyncChain.ts
reckter Aug 1, 2025
e1d4e60
Update src/collections/AsyncChain.ts
reckter Aug 1, 2025
8ed2794
Update src/collections/AsyncChain.ts
reckter Aug 1, 2025
95cf666
Fix takeLastWhile
reckter Aug 1, 2025
afc442c
Fix double evaluation and type casting
reckter Aug 1, 2025
96f31b3
Renaming variable to better suit the function
reckter Aug 1, 2025
e91f90b
add this.startCalculation() to SlidingWindowAyncChain
reckter Aug 1, 2025
75e14bf
Add async condition to takeLastWhile and takeWhile
reckter Aug 1, 2025
0256b95
Also allow async filters for the asyncObjChain filters
reckter Aug 1, 2025
752f0b9
Update src/collections/AsyncChain.ts
reckter Aug 1, 2025
056c96f
Switch to pnpm and update dependencies
reckter Aug 4, 2025
0f3bf10
Fix eslint config
reckter Aug 4, 2025
d4ed1ba
Add missing file
reckter Aug 4, 2025
286b4d9
Add more tests
reckter Aug 4, 2025
b8adec3
Merge branch 'main' into async-chains
reckter Aug 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
"devDependencies": {
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.32.0",
"@types/node": "^24.2.0",
"@typescript-eslint/eslint-plugin": "^8.38.0",
"@typescript-eslint/parser": "^8.38.0",
"auto": "^11.3.0",
"ava": "^6.4.1",
"eslint": "^9.0.0",
"eslint-config-prettier": "^10.1.8",
"prettier": "^3.6.2",
"ts-node": "^10.9.2",
"typescript": "5.8.3"
"typescript": "5.9.2",
"@types/node": "^24.2.0",
"ts-node": "^10.9.2"
},
"prettier": {
"semi": false
Expand Down
118 changes: 59 additions & 59 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 59 additions & 1 deletion src/collections.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from "ava"
import { chain } from "./collections"
import { chain, objChain } from "./collections"

test("should associateBy correctly", (t) => {
const result = chain([1, 2, 3])
Expand Down Expand Up @@ -162,3 +162,61 @@ test("should allow flatMap over sets", (t) => {

t.deepEqual(result, [1, 2, 3, 1])
})

test("chain::mapAsync should be downwards compatible", async (t) => {
const c = chain([1, 2, 3, 4, 5])

const b = await c.mapAsync(async (it) => it * 3)

const result = b.value()

t.deepEqual(result, [3, 6, 9, 12, 15])
})

test("chain::mapAsync should be chainable into an async chain", async (t) => {
const c = chain([1, 2, 3, 4, 5])

const b = await c
.mapAsync(async (it) => it * 3)
.filter(async (it) => it % 2 === 1)
.sortBy(async (it) => -it)

const result = b.value()

t.deepEqual(result, [15, 9, 3])
})

test("The Touched Type should work correctly with object chain", (t) => {
// we do the iife here, so TS doesn't narrow the type further
const result = testTouchedType([{ id: true }] as unknown as Touched<unknown>)

t.deepEqual(result, { "0-mapped": { id: true } })
})

type Touched<Entity> =
| undefined
| true
| (Entity extends ReadonlyArray<unknown>
? {
[X in number]?: Touched<Entity[number]>
}
: Entity extends Array<unknown>
? {
[X in number]?: Touched<Entity[number]>
}
: Entity extends Record<string, unknown>
? {
[K in keyof Entity]?: Touched<Entity[K]>
}
: never)

function testTouchedType<
Entity extends Array<unknown> | ReadonlyArray<unknown>,
>(touched: Touched<Entity>) {
if (touched !== true) {
return objChain(touched)
?.mapKeys((it) => it.toString() + "-mapped")
.value()
}
return false
}
Binary file modified src/collections.test.ts.snap
Binary file not shown.
Loading
Loading