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