pick now accepts lookup tables, with alternate cycle squeezing behaviour as new inhabit function (#918)

- the args for `pick` are now reversed (breaking change!)
- `pick` is also now a method on the inhabited pattern
- `pick` now also accepts a lookup table
- `inhabit` added with same behaviour as `pick`, except cycles from source patterns are squeezed into events of inhabited patterns
- Also some general doc tidying, sorry for the noise..
- There is now also `pickmod` and `inhabitmod`, for wrapping indexes around rather than clamping them
This commit is contained in:
Alex McLean 2024-01-18 16:45:39 +00:00 committed by GitHub
parent 9ba7b9b4d4
commit 873a412179
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 248 additions and 48 deletions

View file

@ -316,3 +316,10 @@ export function hash2code(hash) {
return base64ToUnicode(decodeURIComponent(hash));
//return atob(decodeURIComponent(codeParam || ''));
}
export function objectMap(obj, fn) {
if (Array.isArray(obj)) {
return obj.map(fn);
}
return Object.fromEntries(Object.entries(obj).map(([k, v], i) => [k, fn(v, k, i)]));
}