Skip to content

Commit

Permalink
lensIso use lens
Browse files Browse the repository at this point in the history
  • Loading branch information
Harris-Miller committed Jul 25, 2024
1 parent 7da67a6 commit a25f987
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
14 changes: 14 additions & 0 deletions source/internal/_lens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import map from '../map.js';

export default function _lens(getter, setter) {
return function(toFunctorFn) {
return function(target) {
return map(
function(focus) {
return setter(focus, target);
},
toFunctorFn(getter(target))
);
};
};
}
15 changes: 2 additions & 13 deletions source/lens.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _curry2 from './internal/_curry2.js';
import map from './map.js';
import _lens from './internal/_lens.js';


/**
Expand All @@ -25,16 +25,5 @@ import map from './map.js';
* R.set(xLens, 4, {x: 1, y: 2}); //=> {x: 4, y: 2}
* R.over(xLens, R.negate, {x: 1, y: 2}); //=> {x: -1, y: 2}
*/
var lens = _curry2(function lens(getter, setter) {
return function(toFunctorFn) {
return function(target) {
return map(
function(focus) {
return setter(focus, target);
},
toFunctorFn(getter(target))
);
};
};
});
var lens = _curry2(_lens);
export default lens;
14 changes: 3 additions & 11 deletions source/lensIso.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import _curry2 from './internal/_curry2.js';
import map from './map.js';
import _lens from './internal/_lens.js';
import nAry from './nAry.js';


/**
Expand All @@ -26,15 +27,6 @@ import map from './map.js';
* R.over(xJson, R.assoc('x', 6), '{"x": 4,"y": 2}'); //=> '{"x": 6 ,"y": 2}'
*/
var lensIso = _curry2(function lensIso(to, from) {
return function(toFunctorFn) {
return function(target) {
return map(
function(focus) {
return from(focus);
},
toFunctorFn(to(target))
);
};
};
return _lens(to, nAry(1, from));
});
export default lensIso;

0 comments on commit a25f987

Please sign in to comment.