-
Notifications
You must be signed in to change notification settings - Fork 0
Collection Interface
Jason Barr edited this page Sep 22, 2021
·
2 revisions
All the methods implemented by all iterable sequence collections in this library.
Built on the backbone provided by the iterable functions.
Provides complete equivalence to the JavaScript Array type functionality, plus a lot more.
-
size- the number of items a collection contains all(search)any(search)ap(listOfFunctions)append(item)-
at(index)- returns Option -
atUnsafe(index)- may returnnullorundefined- use with care -
atWithDefault(index, defaultValue)- a better choice thanatUnsafein nearly every circumstance average()chain(fn)clone()-
compact()- removesnullandundefinedvalues from the iterable concat(...others)concatToArray(...others)count(search)copy()copyWithin(target, start, end)difference(other)each(fn)eachWithIndex(fn)-
empty()- returns an empty collection of the same type entries()every(pred)-
exclude(pred)- alias forreject filter(pred)-
find(pred)- returns Option -
findIndex(pred)- returns Option first()-
flat(level)- optionallevelargument defines the level of flatness at which to stop flattening -
flatten(level)- same asflat -
flatMap(fn)- alias forchain -
fold(fn, initial)- alias forreduce -
foldLeft(fn, initial)- alias forreduce -
foldRight(fn, initial)- alias forreduceRight forEach(fn)from(index)-
get(index)- returns Option has(value)includes(value)-
indexOf(search)- returns Option insert(item, index)inspect()intersection(other)isEmpty()isEqual(other)join(sep)keys()-
last()- returns Option -
lastIndexOf(value[, startIndex])- returns Option map(fn)mapWithIndex(fn)-
max()- returns Option -
median()- returns Option -
min()- returns Option none(search)pluck(numItems)-
pop()- returns Option -
product()- returns Option prepend(item)push(item)reduce(fn, initial)reduceRight(fn, initial)-
reject(pred)- the opposite offilter: whatever returns true forpredis excluded from the result remove(search)removeAt(start, end)reverse()-
sample()- returns a random element from the collection sequence(point)shift()shuffle()-
slice(start, end, step)- Python-style slicing some(pred)-
sort({ key="", fn=() => {}, reversed = false })- sorts numbers correctly, unlike the regular arraysort. Provide akeyto sort by an object key, or a function forfnwhen you need more control. splice(start, deleteCount, ...items)-
sum()- returns Option symmetricDifference(other)-
take(numItems)- alias forpluck to(index)toArray()toJSON()toString()traverse(point, fn)union(other)unique()unshift()-
update(index, updater)-updateris a function used to calculate the new value atindex values()-
zip(...others)- potentially unsafe - may zipnullandundefinedvalues