source: node_modules/ramda-adjunct/es/isIterable.js

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

Initial commit

  • Property mode set to 100644
File size: 1.0 KB
Line 
1import { hasIn, curryN } from 'ramda';
2import isFunction from './isFunction';
3
4/**
5 * Checks whether the passed value is iterable.
6 *
7 * @func isIterable
8 * @memberOf RA
9 * @since {@link https://char0n.github.io/ramda-adjunct/2.18.0|v2.18.0}
10 * @category Type
11 * @sig * -> Boolean
12 * @param {*} val The value to test
13 * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol}
14 * @return {boolean}
15 * @example
16 *
17 * RA.isIterable(['arrays', 'are', 'iterable']); //=> true
18 * RA.isIterable('strings are iterable, too'); //=> true
19 * RA.isIterable((function* () {})()); //=> true (generator objects are both iterable and iterators)
20 *
21 * RA.isIterable({}); //=> false
22 * RA.isIterable(-0); //=> false
23 * RA.isIterable(null); //=> false
24 * RA.isIterable(undefined); //=> false
25 */
26var isIterable = curryN(1, function (val) {
27 if (typeof Symbol === 'undefined') {
28 return false;
29 }
30 return hasIn(Symbol.iterator, Object(val)) && isFunction(val[Symbol.iterator]);
31});
32export default isIterable;
Note: See TracBrowser for help on using the repository browser.