JSPM

extra-iterable

2.1.52
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1092
  • Score
    100M100P100Q111418F
  • License MIT

An iterable is a sequence of values.

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 look like:

  • unique(): accepts a compare function (default).
  • uniqueOn(): accepts a map function for faster comparision (map).

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. Each method is also available as separate package for use by bundling tools, like browserify, rollup, uglify-js.

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, 4)];
// [1, 2, 3, 1]

var x = [1, 2, 3, 4];
iterable.reduce(x, (acc, v) => acc+v);
// 10

reference

Method Action
is Checks if value is iterable.
get Gets value at index.
set Sets value at index.
swap Exchanges two values.
index Gets zero-based index.
indexRange Gets index range of part of iterable.
size Counts the number of values.
iterator Gives iterator for iterable.
from Converts iterator to iterable.
fill Fills with given value.
copy Copies part of iterable to another.
concat Appends iterables together.
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.
interleave Places values of an iterable between another.
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.
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.
zip Combines values from iterables.
join Joins values together.
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.
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 which satisfies a test.
findIndex Finds index of leftmost 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.

nodef

Browserified, minified version of this package is extra-iterable.min.