Socket
Socket
Sign inDemoInstall

extra-iterable

Package Overview
Dependencies
0
Maintainers
1
Versions
467
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

extra-iterable

An iterable is a sequence of values.


Version published
Maintainers
1
Weekly downloads
553
decreased by-39.76%

Weekly downloads

Readme

Source

An iterable is a sequence of values.
šŸ“¦ Node.js, šŸŒ Web, šŸ“œ Files, šŸ“° Docs, šŸ“˜ Wiki.

This is a collection of functions for operating upon iterables. 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. To use it on the web, simply use the extra_iterable global variable after loading with a <script> tag from the jsDelivr CDN.

Stability: Experimental.


const xiterable = require('extra-iterable');
// import * as xiterable from "extra-iterable";
// import * as xiterable from "https://unpkg.com/extra-iterable/index.mjs"; (deno)

var x = [2, 4, 6, 8];
xiterable.get(x, 1);
// ā†’ 4

var x = [1, 2, 3, 4];
[...xiterable.swap(x, 0, 1)];
// ā†’ [ 2, 1, 3, 4 ]

var x = [1, 2, 3];
[...xiterable.cycle(x, 0, 4)];
// ā†’ [1, 2, 3, 1]

var x = [1, 2, 3, 4];
xiterable.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.
indexRangeGet 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.
cycleObtain 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.
unionObtain values present in any iterable.
intersectionObtain values present in both iterables.
differenceObtain values not present in another iterable.
symmetricDifferenceObtain values not present in both iterables.
cartesianProductList cartesian product of iterables.



ORG DOI Coverage Status Test Coverage Maintainability

Keywords

FAQs

Last updated on 19 Oct 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with āš”ļø by Socket Inc