deep-iterable
Requirements
- Node >= 6.0.0
Features
- Traverse at the lowest level of iterables
Usage
Constructor
var DeepIterable = ;var result = base deeper shallower preprocess;
Where:
-
DeepIterable
is a ECMAScript 6 class -
base
is either the first argument ofpreprocess
or an iterable object -
deeper
(optional) is a function which determines should the iteration process goes deeper -
shallower
(optional) is a function which would be called each times the iteration process escape a sub-iterable -
preprocess
(optional) is a function which should creates and returns iterable objects from passed elements -
result
which is an instance of classDeepIterable
, is an iterable object
Examples
With a base iterable only
var tree = 'abc' 'def' 'ghi' 'jkl' 'mno' 'pqrs' ...'tuv' ...'wxyz';var iterable = tree;console; // You would seen an array of alphabet-subsequences
deeper
Plus a deep determiner: var tree = 'abc' 'def' ...'ghi';var !iterable instanceof Set;var iterable = tree;console; // You would seen an array of ECMAScript Set objects
shallower
Plus an on-escape reactor: var tree = 'abc' 'def' 'ghi' 'jkl' 'mno' 'pqrs' ...'tuv' ...'wxyz';var { console; return typeof child !== 'string' || childlength > 1; // You don't want an infinite iteration, right?};var console;var iterable = tree deeper shallower;iterable; // You would seen many entering/escaping logs
preprocess
Plus a sub-iterables/elements creator: var universe = Chaos: Tartarus: Typhon: {} Gaia: Uranus: Aphrodite: {} Cyclopes: {} Cronus: Zeus: Appollo: {} Artemis: {} Athena: {} Ares: {} Hephaestus: {} Hera: Ares: {} Hephaestus: {} Poseidon: {} Hestia: {} Hades: {} Demeter: {} Rhea: {} Ourea: {} Pontus: {} ; var typeof iterable !== 'string'; var { if typeof object === 'string' return object; var first = Object; var second = first; return ...first ...second;}; var iterable = universe deeper undefined preprocess;console; // You would seen all the names listed above