You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.2 KiB

4 years ago
  1. import filter from "./filter.js";
  2. import juxt from "./juxt.js";
  3. import reject from "./reject.js";
  4. /**
  5. * Takes a predicate and a list or other `Filterable` object and returns the
  6. * pair of filterable objects of the same type of elements which do and do not
  7. * satisfy, the predicate, respectively. Filterable objects include plain objects or any object
  8. * that has a filter method such as `Array`.
  9. *
  10. * @func
  11. * @memberOf R
  12. * @since v0.1.4
  13. * @category List
  14. * @sig Filterable f => (a -> Boolean) -> f a -> [f a, f a]
  15. * @param {Function} pred A predicate to determine which side the element belongs to.
  16. * @param {Array} filterable the list (or other filterable) to partition.
  17. * @return {Array} An array, containing first the subset of elements that satisfy the
  18. * predicate, and second the subset of elements that do not satisfy.
  19. * @see R.filter, R.reject
  20. * @example
  21. *
  22. * R.partition(R.includes('s'), ['sss', 'ttt', 'foo', 'bars']);
  23. * // => [ [ 'sss', 'bars' ], [ 'ttt', 'foo' ] ]
  24. *
  25. * R.partition(R.includes('s'), { a: 'sss', b: 'ttt', foo: 'bars' });
  26. * // => [ { a: 'sss', foo: 'bars' }, { b: 'ttt' } ]
  27. */
  28. var partition =
  29. /*#__PURE__*/
  30. juxt([filter, reject]);
  31. export default partition;