Skip to content

Commit

Permalink
better definition of reusable general map
Browse files Browse the repository at this point in the history
  • Loading branch information
sadasant committed Feb 27, 2017
1 parent 0e3fdbe commit a84257f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export const flowMap = (...fns) => _.map(_.flow(...fns))
// Algebras
// --------
const isTraversable = x => _.isArray(x) || _.isPlainObject(x)
const getMap = x => _.isArray(x) ? _.map : _.mapValues
export const map = _.curry((f, x) => (_.isArray(x) ? _.map : _.mapValues)(f, x))
// Map for any recursive algebraic data structure
// defaults in multidimensional arrays and recursive plain objects
export const deepMap = _.curry((fn, obj, map = null, is = isTraversable) =>
(map || getMap(obj))(e => is(e) ? deepMap(fn, fn(e), map, is) : e, obj))
export const deepMap = _.curry((fn, obj, _map = map, is = isTraversable) =>
_map(e => is(e) ? deepMap(fn, fn(e), _map, is) : e, obj))

// Misc
// ----
Expand Down

0 comments on commit a84257f

Please sign in to comment.