Skip to content

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.

Instance Properties and Methods

  • size - the number of items a collection contains
  • all(search)
  • any(search)
  • ap(listOfFunctions)
  • append(item)
  • at(index) - returns Option
  • atUnsafe(index) - may return null or undefined - use with care
  • atWithDefault(index, defaultValue) - a better choice than atUnsafe in nearly every circumstance
  • average()
  • chain(fn)
  • clone()
  • compact() - removes null and undefined values 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 for reject
  • filter(pred)
  • find(pred) - returns Option
  • findIndex(pred) - returns Option
  • first()
  • flat(level) - optional level argument defines the level of flatness at which to stop flattening
  • flatten(level) - same as flat
  • flatMap(fn) - alias for chain
  • fold(fn, initial) - alias for reduce
  • foldLeft(fn, initial) - alias for reduce
  • foldRight(fn, initial) - alias for reduceRight
  • 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 of filter: whatever returns true for pred is 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 array sort. Provide a key to sort by an object key, or a function for fn when you need more control.
  • splice(start, deleteCount, ...items)
  • sum() - returns Option
  • symmetricDifference(other)
  • take(numItems) - alias for pluck
  • to(index)
  • toArray()
  • toJSON()
  • toString()
  • traverse(point, fn)
  • union(other)
  • unique()
  • unshift()
  • update(index, updater) - updater is a function used to calculate the new value at index
  • values()
  • zip(...others) - potentially unsafe - may zip null and undefined values

Clone this wiki locally