JSPM

extra-iterable

2.4.22
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 896
  • Score
    100M100P100Q112109F
  • License MIT

An iterable is a sequence of values.

Package Exports

  • extra-iterable

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');
// import * as iterable from 'extra-iterable';
// import * as iterable from 'https://unpkg.com/extra-iterable@2.3.36/index.mjs'; (deno)

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);
// 10

reference

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 when test passes.
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 entry.
max Finds largest entry.
range Finds smallest and largest entries.
map Updates values based on map function.
reduce Reduces values to a single value.
filter Keeps the values which pass a test.
take Extracts values from iterable.
drop Drops 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 not present in another iterable.
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 Searches 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 first value passing a test.
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.

nodef