diff options
| author | bozo.kopic <bozo.kopic@gmail.com> | 2017-07-02 02:45:51 +0200 |
|---|---|---|
| committer | bozo.kopic <bozo.kopic@gmail.com> | 2017-07-02 02:45:51 +0200 |
| commit | c75e05b2fcbd08ec77a2ac85837f9f58829a44f6 (patch) | |
| tree | 446e9f371f0847b78832a8ff5594c56e6c891d7b /src_js/hatter/lenses.js | |
| parent | 268bb2951c9026e8935c0a99d188416422351a0e (diff) | |
build environment and basic folder structure
Diffstat (limited to 'src_js/hatter/lenses.js')
| -rw-r--r-- | src_js/hatter/lenses.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src_js/hatter/lenses.js b/src_js/hatter/lenses.js new file mode 100644 index 0000000..39da314 --- /dev/null +++ b/src_js/hatter/lenses.js @@ -0,0 +1,21 @@ +import R from 'ramda'; + + +export const index = R.lensIndex; + +export const prop = R.lensProp; + +export function path(...xs) { + return R.reduce((acc, i) => R.compose(acc, pathParamToLens(i)), + R.identity, xs); +} + +function pathParamToLens(x) { + switch (typeof(x)) { + case 'function': return x; + case 'number': return index(x); + case 'string': return prop(x); + case 'object': if (Array.isArray(x)) return R.apply(path, x); + } + throw 'Invalid path parameter'; +} |
