source: node_modules/ramda/es/take.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.6 KB
Line 
1import _curry2 from "./internal/_curry2.js";
2import _dispatchable from "./internal/_dispatchable.js";
3import _xtake from "./internal/_xtake.js";
4import slice from "./slice.js";
5/**
6 * Returns the first `n` elements of the given list, string, or
7 * transducer/transformer (or object with a `take` method).
8 *
9 * Dispatches to the `take` method of the second argument, if present.
10 *
11 * @func
12 * @memberOf R
13 * @since v0.1.0
14 * @category List
15 * @sig Number -> [a] -> [a]
16 * @sig Number -> String -> String
17 * @param {Number} n
18 * @param {*} list
19 * @return {*}
20 * @see R.drop
21 * @example
22 *
23 * R.take(1, ['foo', 'bar', 'baz']); //=> ['foo']
24 * R.take(2, ['foo', 'bar', 'baz']); //=> ['foo', 'bar']
25 * R.take(3, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
26 * R.take(4, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
27 * R.take(3, 'ramda'); //=> 'ram'
28 *
29 * const personnel = [
30 * 'Dave Brubeck',
31 * 'Paul Desmond',
32 * 'Eugene Wright',
33 * 'Joe Morello',
34 * 'Gerry Mulligan',
35 * 'Bob Bates',
36 * 'Joe Dodge',
37 * 'Ron Crotty'
38 * ];
39 *
40 * const takeFive = R.take(5);
41 * takeFive(personnel);
42 * //=> ['Dave Brubeck', 'Paul Desmond', 'Eugene Wright', 'Joe Morello', 'Gerry Mulligan']
43 * @symb R.take(-1, [a, b]) = [a, b]
44 * @symb R.take(0, [a, b]) = []
45 * @symb R.take(1, [a, b]) = [a]
46 * @symb R.take(2, [a, b]) = [a, b]
47 */
48
49var take =
50/*#__PURE__*/
51_curry2(
52/*#__PURE__*/
53_dispatchable(['take'], _xtake, function take(n, xs) {
54 return slice(0, n < 0 ? Infinity : n, xs);
55}));
56
57export default take;
Note: See TracBrowser for help on using the repository browser.