@ende/collections
ende add jsr:@ende/collectionsVersion 2026.10.15 on JSR.
Pure functions for common tasks around collection types like arrays and objects.
Inspired by Kotlin's Collections package and Lodash.
import { intersect, sample, pick } from "@ende/collections";
import { assertEquals, assertArrayIncludes } from "@ende/assert";
const lisaInterests = ["Cooking", "Music", "Hiking"];
const kimInterests = ["Music", "Tennis", "Cooking"];
assertEquals(intersect(lisaInterests, kimInterests), ["Cooking", "Music"]);
assertArrayIncludes(lisaInterests, [sample(lisaInterests)]);
const cat = { name: "Lulu", age: 3, breed: "Ragdoll" };
assertEquals(pick(cat, ["name", "breed"]), { name: "Lulu", breed: "Ragdoll"});
Modules
@ende/collections/aggregate-groups@ende/collections/associate-by@ende/collections/associate-with@ende/collections/chunk@ende/collections/deep-merge@ende/collections/distinct@ende/collections/distinct-by@ende/collections/drop-last-while@ende/collections/drop-while@ende/collections/filter-entries@ende/collections/filter-keys@ende/collections/filter-values@ende/collections/find-single@ende/collections/first-not-nullish-of@ende/collections/includes-value@ende/collections/interleave@ende/collections/intersect@ende/collections/invert@ende/collections/invert-by@ende/collections/join-to-string@ende/collections/map-entries@ende/collections/map-keys@ende/collections/map-not-nullish@ende/collections/map-values@ende/collections/max-by@ende/collections/max-of@ende/collections/max-with@ende/collections/min-by@ende/collections/min-of@ende/collections/min-with@ende/collections/omit@ende/collections/partition@ende/collections/partition-entries@ende/collections/permutations@ende/collections/pick@ende/collections/reduce-groups@ende/collections/running-reduce@ende/collections/sample@ende/collections/sliding-windows@ende/collections/sort-by@ende/collections/sum-of@ende/collections/take-last-while@ende/collections/take-while@ende/collections/union@ende/collections/unstable-binary-search@ende/collections/unstable-cycle@ende/collections/unzip@ende/collections/without-all@ende/collections/zip
Exports
aggregateGroups— Applies the given aggregator to each group in the given grouping, returning the results together with the respective group keysArrayValueType— Get array values typeassociateBy— Creates a record by associating each element of the input array with a key generated by the selector function.associateWith— Associates each string element of an array with a value returned by a selector function.chunk— Splits the given array into an array of chunks of the given size and returns them.deepMerge— Merges the two given records, recursively merging any nested records with the second collection overriding the first in case of conflict.DeepMerge— Merge deeply two objectsDeepMergeOptions— Options for deepMerge.distinct— Returns all distinct elements in the given array, preserving order by first occurrence.distinctBy— Returns all elements in the given array that produce a unique value using the given discriminator, with the first matching occurrence retained.dropLastWhile— Returns an array that drops all elements in the given iterable until the last element that does not match the given predicate.dropWhile— Returns an array that drops all elements in the given iterable until the first element that does not match the given predicate.ExpandRecursively— Force intellisense to expand the typing to hide merging typingsfilterEntries— Returns a new record with all entries of the given record except the ones that do not match the given predicate.filterKeys— Returns a new record with all entries of the given record except the ones that have a key that does not match the given predicate.filterValues— Returns a new record with all entries of the given record except the ones that have a value that does not match the given predicate.findSingle— Returns an element if and only if that element is the only one matching the given condition. Returns `undefined` otherwise.firstNotNullishOf— Applies the given selector to elements in the given array until a value is produced that is neither `null` nor `undefined` and returns that value. Returns `undefined` if no such value is produced.includesValue— Returns true if the given value is part of the given object, otherwise it returns false.interleave— Returns all elements from the given iterables in round-robin order. Unlike zip, which stops at the shortest iterable and returns tuples, `interleave` continues until all input iterables are exhausted and returns a flat array. All input iterables are consumed eagerly.intersect— Returns all distinct elements that appear at least once in each of the given iterables.invert— Composes a new record with all keys and values inverted.invertBy— Composes a new record with all keys and values inverted.InvertByResult— Return type for invertBy.InvertResult— Return type for invert.joinToString— Transforms the elements in the given array to strings using the given selector. Joins the produced strings into one using the given `separator` and applying the given `prefix` and `suffix` to the whole string afterwards.JoinToStringOptions— Options for joinToString.mapEntries— Applies the given transformer to all entries in the given record and returns a new record containing the results.mapKeys— Applies the given transformer to all keys in the given record's entries and returns a new record containing the transformed entries.MapKeyType— Get map values typesmapNotNullish— Returns a new array, containing all elements in the given array transformed using the given transformer, except the ones that were transformed to `null` or `undefined`.mapValues— Applies the given transformer to all values in the given record and returns a new record containing the resulting keys associated to the last value that produced them.MapValueType— Get map values typesmaxBy— Returns the first element that is the largest value of the given function or undefined if there are no elements.maxOf— Applies the given selector to all elements of the provided collection and returns the max value of all elements. If an empty array is provided the function will return undefined.maxWith— Returns the first element having the largest value according to the provided comparator or undefined if there are no elements.Merge— Merge two objectsMergeAllArrays— Merge all arrays types definitions from keys present in both objectsMergeAllMaps— Merge all maps types definitions from keys present in both objectsMergeAllRecords— Merge all records types definitions from keys present in both objectsMergeAllSets— Merge all sets types definitions from keys present in both objectsMergeRightOmitComplexes— Merge two objects, with left precedenceMergingStrategy— Merging strategyminBy— Returns the first element that is the smallest value of the given function or undefined if there are no elements.minOf— Applies the given selector to all elements of the given collection and returns the min value of all elements. If an empty array is provided the function will return undefined.minWith— Returns the first element having the smallest value according to the provided comparator or undefined if there are no elements.ObjectXorKeys— Object with keys in either T or U but not in bothomit— Creates a new object by excluding the specified keys from the provided object.OmitComplexes— Exclude map, sets and array from typeOrder— Order option for SortByOptions.PartialByType— Filter of keys matching a given typepartition— Returns a tuple of two arrays with the first one containing all elements in the given array that match the given predicate and the second one containing all that do not.partitionEntries— Returns a tuple of two records with the first one containing all entries of the given record that match the given predicate and the second one containing all that do not.permutations— Builds all possible orders of all elements in the given array. Ignores equality of elements, meaning this will always return the same number of permutations for a given length of input.pick— Creates a new object by including the specified keys from the provided object.reduceGroups— Applies the given reducer to each group in the given grouping, returning the results together with the respective group keys.runningReduce— Calls the given reducer on each element of the given collection, passing its result as the accumulator to the next respective call, starting with the given initialValue. Returns all intermediate accumulator results.sample— Returns a random element from the given iterable.SetValueType— Get set values typeslidingWindows— Generates sliding views of the given iterable of the given size and returns an array containing all of them.SlidingWindowsOptions— Options for slidingWindows.sortBy— Returns all elements in the given collection, sorted by their result using the given selector. The selector function is called only once for each element. Ascending or descending order can be specified through the `order` option. By default, the elements are sorted in ascending order.SortByOptions— Options for sortBy.sumOf— Applies the given selector to all elements in the given collection and calculates the sum of the results.takeLastWhile— Returns all elements in the given iterable after the last element that does not match the given predicate.takeWhile— Returns all elements in the given collection until the first element that does not match the given predicate.union— Returns all distinct elements that appear in any of the given arrays.unzip— Builds two separate arrays from the given array of 2-tuples, with the first returned array holding all first tuple elements and the second one holding all the second elements.withoutAll— Returns an array excluding all given values from an iterable.zip— Builds N-tuples of elements from the given N iterables with matching indices, stopping when the shortest iterable is exhausted.