Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

extra-iterable

Package Overview
Dependencies
Maintainers
1
Versions
468
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extra-iterable

A collection of functions for operating upon iterables.

  • 3.2.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.9K
increased by81.59%
Maintainers
1
Weekly downloads
 
Created
Source

A collection of functions for operating upon iterables.
📦 Node.js, 🌐 Web, 📜 Files, 📰 Docs, 📘 Wiki.

An iterable is a sequence of values. Assumption here is that an iterable can only be iterated over once. Methods which require multiple iterations preserve old values in a backup array using toMany. Many methods accept both compare and map functions, and in some cases using only a map function enables faster comparision (like unique). I borrowed a lot of ideas from Haskell, Elm, Python, Basic, Lodash, and other NPM packages. These are mentioned in references of each method.

This package is available in Node.js and Web formats. The web format is exposed as extra_iterable standalone variable and can be loaded from jsDelivr CDN.

Stability: Experimental.


const iterable = require('extra-iterable');
// import * as iterable from "extra-iterable";
// import * as iterable from "https://unpkg.com/extra-iterable/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


Index

PropertyDescription
isCheck if value is an iterable.
isIteratorCheck if value is an iterator.
isListCheck if value is a list (iterable & !string).
iteratorGet iterator of an iterable.
keysList all indices.
valuesList all values.
entriesList all index-value pairs.
fromConvert an iterable-like to iterable.
fromIteratorConvert an iterator to iterable.
fromRangeGenerate iterable from given number range.
fromInvocationGenerate iterable from repeated function invocation.
fromApplicationGenerate iterable from repeated function application.
isOnceCheck if an iterable can iterated only once.
isManyCheck if an iterable can be iterated many times.
toManyConvert a once-like iterable to many.
toInvokableGenerate a function that iterates over values upon invocation.
isEmptyCheck if an iterable is empty.
lengthFind the length of an iterable.
compareCompare two iterables.
isEqualCheck if two iterables are equal.
indexGet zero-based index for element in iterable.
indexRangeGets index range for part of iterable.
getGet value at index.
getAllGet values at indices.
getPathGet value at path in a nested iterable.
hasPathCheck if nested iterable has a path.
setSet value at index.
swapExchange two values.
removeRemove value at index.
countCount values which satisfy a test.
countAsCount occurrences of values.
minFind smallest value.
maxFind largest value.
rangeFind smallest and largest values.
minEntryFind smallest entry.
maxEntryFind largest entry.
rangeEntriesFind smallest and largest entries.
sliceGet part of an iterable.
headGet first value.
lastGet last value.
tailGet values except first.
initGet values except last.
leftGet values from left.
rightGet values from right.
middleGet values from middle.
takeKeep first n values only.
takeRightKeep last n values only.
takeWhileKeep values from left, while a test passes.
takeWhileRightKeep values from right, while a test passes.
dropDiscard first n values only.
dropRightDiscard last n values only.
dropWhileDiscard values from left, while a test passes.
dropWhileRightDiscard values from right, while a test passes.
includesCheck if iterable has a value.
indexOfFind first index of a value.
lastIndexOfFind last index of a value.
findFind first value passing a test.
findRightFind last value passing a test.
scanWhileScan from left, while a test passes.
scanWhileRightScan from right, while a test passes.
scanUntilScan from left, until a test passes.
scanUntilRightScan from right, until a test passes.
searchFind index of first value passing a test.
searchRightFind index of last value passing a test.
searchAllFind indices of values passing a test.
searchValueFind first index of a value.
searchValueRightFind last index of a value.
searchValueAllFind indices of a value.
searchInfixFind first index of an infix.
searchInfixRightFind last index of an infix.
searchInfixAllFind indices of an infix.
searchSubsequenceFind first index of a subsequence.
hasValueCheck if iterable has a value.
hasPrefixCheck if iterable starts with a prefix.
hasSuffixCheck if iterable ends with a suffix.
hasInfixCheck if iterable contains an infix.
hasSubsequenceCheck if iterable has a subsequence.
forEachCall a function for each value.
someCheck if any value satisfies a test.
everyCheck if all values satisfy a test.
mapTransform values of an iterable.
reduceReduce values of iterable to a single value.
filterKeep the values which pass a test.
filterAtKeep the values at given indices.
rejectDiscard the values which pass a test.
rejectAtDiscard the values at given indices.
accumulateProduce accumulating values.
flatFlatten nested iterable to given depth.
flatMapFlatten nested iterable, based on map function.
zipCombine values from iterables.
fillFill with given value.
pushAdd values to the end.
unshiftAdd values to the start.
copyCopy part of iterable to another.
copyWithinCopy part of iterable within.
moveWithinMove part of iterable within.
spliceRemove or replaces existing values.
splitBreak iterable considering test as separator.
splitAtBreak iterable considering indices as separator.
cutBreak iterable when test passes.
cutRightBreak iterable after test passes.
cutAtBreak iterable at given indices.
cutAtRightBreak iterable after given indices.
groupKeep similar values together and in order.
partitionSegregate values by test result.
partitionAsSegregate values by similarity.
chunkBreak iterable into chunks of given size.
cycleGive values that cycle through an iterable.
repeatRepeat an iterable given times.
reverseReverse the values.
rotateRotate values in iterable.
interspersePlace a separator between every value.
interpolateEstimate new values between existing ones.
intermixPlace values of an iterable between another.
interleavePlace values from iterables alternately.
concatAppend values from iterables.
mergeMerge values from sorted iterables.
joinJoin values together into a string.
isUniqueCheck if there are no duplicate values.
isDisjointChecks if arrays have no value in common.
uniqueRemove duplicate values.
unionGive values present in any iterable.
intersectionGive values present in both iterables.
differenceGive values not present in another iterable.
symmetricDifferenceGive values not present in both iterables.
cartesianProductList cartesian product of iterables.



ORG DOI Coverage Status Test Coverage Maintainability

Keywords

FAQs

Package last updated on 23 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc