-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(transducers): use arrow fns
- Loading branch information
1 parent
6eba241
commit e9f0542
Showing
33 changed files
with
267 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export function constantly<T>(x: T): (...args: any[]) => T { | ||
return () => x; | ||
} | ||
export const constantly = | ||
<T>(x: T): (...args: any[]) => T => () => x; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export function delay<T>(x: T, t: number) { | ||
return new Promise((resolve) => setTimeout(() => resolve(x), t)); | ||
} | ||
export const delay = | ||
<T>(x: T, t: number) => | ||
new Promise((resolve) => setTimeout(() => resolve(x), t)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { illegalArgs } from "@thi.ng/errors/illegal-arguments"; | ||
|
||
export function ensureIterable(x: any): IterableIterator<any> { | ||
if (!(x != null && x[Symbol.iterator])) { | ||
illegalArgs(`value is not iterable: ${x}`); | ||
} | ||
return x; | ||
} | ||
export const ensureIterable = | ||
(x: any): IterableIterator<any> => { | ||
if (!(x != null && x[Symbol.iterator])) { | ||
illegalArgs(`value is not iterable: ${x}`); | ||
} | ||
return x; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export function identity<T>(x: T) { return x; } | ||
export const identity = <T>(x: T) => x; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { renamer } from "./renamer"; | ||
|
||
export function keySelector(keys: PropertyKey[]) { | ||
return renamer(keys.reduce((acc, x) => (acc[x] = x, acc), {})); | ||
} | ||
export const keySelector = | ||
(keys: PropertyKey[]) => | ||
renamer(keys.reduce((acc, x) => (acc[x] = x, acc), {})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
import { IObjectOf } from "@thi.ng/api/api"; | ||
|
||
export function renamer(kmap: IObjectOf<PropertyKey>) { | ||
const ks = Object.keys(kmap); | ||
const [a2, b2, c2] = ks; | ||
const [a1, b1, c1] = ks.map((k) => kmap[k]); | ||
switch (ks.length) { | ||
case 3: | ||
return (x) => { | ||
const res: any = {}; | ||
let v; | ||
v = x[c1], v !== undefined && (res[c2] = v); | ||
v = x[b1], v !== undefined && (res[b2] = v); | ||
v = x[a1], v !== undefined && (res[a2] = v); | ||
return res; | ||
}; | ||
case 2: | ||
return (x) => { | ||
const res: any = {}; | ||
let v; | ||
v = x[b1], v !== undefined && (res[b2] = v); | ||
v = x[a1], v !== undefined && (res[a2] = v); | ||
return res; | ||
}; | ||
case 1: | ||
return (x) => { | ||
const res: any = {}; | ||
let v = x[a1]; | ||
v !== undefined && (res[a2] = v); | ||
return res; | ||
}; | ||
default: | ||
return (x) => { | ||
let k, v; | ||
const res: any = {}; | ||
for (let i = ks.length - 1; i >= 0; i--) { | ||
k = ks[i], v = x[kmap[k]], v !== undefined && (res[k] = v); | ||
} | ||
return res; | ||
}; | ||
} | ||
} | ||
export const renamer = | ||
(kmap: IObjectOf<PropertyKey>) => { | ||
const ks = Object.keys(kmap); | ||
const [a2, b2, c2] = ks; | ||
const [a1, b1, c1] = ks.map((k) => kmap[k]); | ||
switch (ks.length) { | ||
case 3: | ||
return (x) => { | ||
const res: any = {}; | ||
let v; | ||
v = x[c1], v !== undefined && (res[c2] = v); | ||
v = x[b1], v !== undefined && (res[b2] = v); | ||
v = x[a1], v !== undefined && (res[a2] = v); | ||
return res; | ||
}; | ||
case 2: | ||
return (x) => { | ||
const res: any = {}; | ||
let v; | ||
v = x[b1], v !== undefined && (res[b2] = v); | ||
v = x[a1], v !== undefined && (res[a2] = v); | ||
return res; | ||
}; | ||
case 1: | ||
return (x) => { | ||
const res: any = {}; | ||
let v = x[a1]; | ||
v !== undefined && (res[a2] = v); | ||
return res; | ||
}; | ||
default: | ||
return (x) => { | ||
let k, v; | ||
const res: any = {}; | ||
for (let i = ks.length - 1; i >= 0; i--) { | ||
k = ks[i], v = x[kmap[k]], v !== undefined && (res[k] = v); | ||
} | ||
return res; | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
export function shuffleN(buf: any[], n: number) { | ||
const l = buf.length; | ||
n = n < l ? n : l; | ||
while (--n >= 0) { | ||
const a = (Math.random() * l) | 0; | ||
const b = (Math.random() * l) | 0; | ||
const t = buf[a]; | ||
buf[a] = buf[b]; | ||
buf[b] = t; | ||
} | ||
} | ||
export const shuffleN = | ||
(buf: any[], n: number) => { | ||
const l = buf.length; | ||
n = n < l ? n : l; | ||
while (--n >= 0) { | ||
const a = (Math.random() * l) | 0; | ||
const b = (Math.random() * l) | 0; | ||
const t = buf[a]; | ||
buf[a] = buf[b]; | ||
buf[b] = t; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.