/
objOfOver.js
38 lines (35 loc) 路 1.05 KB
/
objOfOver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { converge, set } from 'ramda';
import headArg from './headArg';
import alwaysEmptyObject from './alwaysEmptyObject';
import viewWith from './viewWith';
/**
* Firstly applies transformation on input data structure according to provided "lens".
* Returning value is made by the "setting" the portion
* of the result focused by the given `lens`.
*
* @func
* @category Object
*
*
* @param {Object} lens Lens
* @param {function} tranformation Transformation function
* @param {any} input
* @returns {Object} Firstly applies transformation on `input` according to `lens` (`R.over`)
* and than returning value is made by the "setting" (`R.set`) the portion
* of previous result focused by the given `lens`.
*
* @example
*
* R_.objOfOver(
* R.lensPath(['a', 'b']),
* (x) => "Hello " + x,
* {
* a: { b: 'foo' },
* c: 'bar',
* }
* )
* // { a: { b: "Hello foo" } }
*
*/
const objOfOver = converge(set, [headArg, viewWith, alwaysEmptyObject]);
export default objOfOver;