Package Exports
- extra-iterable
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (extra-iterable) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
An iterable is a sequence of values. 🏃 📼 📦 🌔 📒
Methods as separate packages:
@extra-iterable/swap: use rollup to bundle this es module.@extra-iterable/swap.min: use in browser (browserify, uglify-js).
Some methods accept a map function for faster comparision (like unique).
I find this map-approach beautiful, which i learned from Haskell's sortOn().
You can notice that i have followed Javascript naming scheme as far as possible.
Some names are borrowed from Haskell, Python, Java, Processing.
Stability: Experimental.
const iterable = require('extra-iterable');
var x = [2, 4, 6, 8];
iterable.get(x, 1);
// 4
var x = [1, 2, 3, 4];
[...iterable.swap(x, 0, 1)];
// [ 2, 1, 3, 4 ]
var x = [1, 2, 3];
[...iterable.cycle(x, 0, 4)];
// [1, 2, 3, 1]
var x = [1, 2, 3, 4];
iterable.reduce(x, (acc, v) => acc+v);
// 10reference
| Method | Action |
|---|---|
| is | Checks if value is iterable. |
| get | Gets value at index. |
| set | Sets value at index. |
| swap | Exchanges two values. |
| head | Gets first value. |
| index | Gets zero-based index. |
| indexRange | Gets index range of part of iterable. |
| size | Counts the number of values. |
| entries | Lists all index-value pairs. |
| iterator | Gives iterator for iterable. |
| many | Converts a once iterable to many. |
| from | Converts iterator to iterable. |
| push | Adds values to the end. |
| fill | Fills with given value. |
| copy | Copies part of iterable to another. |
| concat | Appends iterables together. |
| left | Gets values from the left. |
| slice | Gets part of an iterable. |
| splice | Removes or replaces existing values. |
| flat | Flattens nested iterable to given depth. |
| cut | Breaks iterable at given indices. |
| chunk | Breaks iterable into chunks of given size. |
| cycle | Gives values that cycle through an iterable. |
| repeat | Repeats an iterable given times. |
| reverse | Reverses the values. |
| rotate | Rotates values in iterable. |
| interleave | Merges values from iterables. |
| merge | Merges values from sorted iterables. |
| min | Finds smallest value. |
| max | Finds largest value. |
| range | Finds smallest and largest values. |
| map | Updates values based on map function. |
| reduce | Reduces values to a single value. |
| filter | Keeps the values which pass a test. |
| take | Extracts given number of values from iterable. |
| drop | Drops given number of values from iterable. |
| count | Counts values which satisfy a test. |
| partition | Segregates values by test result. |
| group | Keeps similar values together and in order. |
| split | Breaks iterable considering test as separator. |
| join | Joins values together. |
| cartesianProduct | Lists cartesian product of iterables. |
| zip | Combines values from iterables. |
| unique | Removes duplicate values. |
| union | Gives values present in any iterable. |
| intersection | Gives values present in both iterables. |
| difference | Gives values of an iterable not present in another. |
| isUnique | Checks if there are no duplicate values. |
| isDisjoint | Checks if iterables have no value in common. |
| isValue | Checks if iterable has a value. |
| isPrefix | Checks if iterable starts with a prefix. |
| isInfix | Checks if iterable contains an infix. |
| isSuffix | Checks if iterable ends with a suffix. |
| isSubsequence | Checks if iterable has a subsequence. |
| isEqual | Checks if two iterables are equal. |
| compare | Compares two iterables. |
| search | Searches a value from left. |
| find | Finds first value passing a test. |
| findIndex | Finds index of first value passing a test. |
| some | Checks if any value satisfies a test. |
| every | Checks if all values satisfy a test. |
| forEach | Calls a function for each value. |