Ramda Adjunct 4.0.0

spreadProp.js

  1. import { of, curry } from 'ramda';
  2. import spreadPath from './spreadPath';
  3. /**
  4. * Spreads object under property onto provided object.
  5. * It's like {@link RA.flattenProp|flattenProp}, but removes object under the property.
  6. *
  7. * @func spreadProp
  8. * @memberOf RA
  9. * @since {@link https://char0n.github.io/ramda-adjunct/1.19.0|v1.19.0}
  10. * @category Object
  11. * @typedef Idx = String | Int
  12. * @sig Idx -> {k: v} -> {k: v}
  13. * @param {!string|number} prop The property to spread
  14. * @param {!Object} obj The provided object
  15. * @return {!Object} The result of the spread
  16. * @see {@link RA.spreadPath|spreadPath}, {@link RA.flattenProp|flattenProp}
  17. * @example
  18. *
  19. * RA.spreadProp('b', { a: 1, b: { c: 3, d: 4 } }); // => { a: 1, c: 3, d: 4 };
  20. */
  21. const spreadProp = curry((prop, obj) => spreadPath(of(Array, prop), obj));
  22. export default spreadProp;