List

Linked lists hold zero, one, or more elements in the chosen order. Also called "arrays" in other languages.

asciiPrintable

Filters a list of strings to only include those that contain printable ASCII characters.

const strings = ["Hello", "World", "Lol", "🚀", "123", "αβγ"];
const filteredStrings = asciiPrintable(strings);
console.log(filteredStrings);
// => ['Hello', 'World', 'LoL', '123']

duplicate

Creates a new list by concatenating the given list with itself.

const fruits = ["apple", "banana", "orange"];
const duplicatedFruits = duplicateItems(fruits);
console.log(duplicatedFruits);
// => ['apple', 'banana', 'orange', 'apple', 'banana', 'orange']

flattenList

Flattens a list of arrays into a single-level array.

const nestedList = [
    [1, 2, 3],
    [4, 5],
    [6, 7, 8, 9],
];
const flattenedList = flattenList(nestedList);
console.log(flattenedList);
// => [1, 2, 3, 4, 5, 6, 7, 8, 9]

foldl

Applies a function to each element of a list from left to right and accumulates the results.

const numbers = [1, 2, 3, 4, 5];
const sum = foldl(numbers, 0, (acc, current) => acc + current);
console.log(sum);
// => 15
 
const words = ["Hello", "World", "!"];
const concatenated = foldl(words, "", (acc, current) => acc + " " + current);
console.log(concatenated);
// => ' Hello World !'

foldr

Applies a function to each element of a list from right to left and accumulates the results.

const numbers = [1, 2, 3, 4, 5];
const sum = foldr(numbers, 0, (value, acc) => value + acc);
console.log(sum);
// => 15
 
const words = ["Hello", "World", "!"];
const concatenated = foldr(words, "", (acc, current) => acc + " " + current);
console.log(concatenated);
// => 'Hello World !'

frequencies

Counts the frequencies of elements in a collection and returns a Map with the elements as keys and their frequencies as values.

const numbers = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4];
const frequencyMap = frequencies(numbers);
console.log(frequencyMap);
// => Map(4) { 1 => 1, 2 => 2, 3 => 3, 4 => 4 }

fromStruct

Converts a struct-like object to a regular object where the keys are of type keyof T and the values are of type unknown.

const myStruct = { field1: "value1", field2: 42 };
const myMap = fromStruct(myStruct);
console.log(myMap);
// => { field1: 'value1', field2: 42 }

keyDelete

Deletes items from a list of objects based on a specific key value.

const data = [
    { key: "a", value: 1 },
    { key: "b", value: 2 },
    { key: "c", value: 3 },
    { key: "d", value: 4 },
];
 
const filtered = keyDelete(data, "b");
console.log(filtered);
// => [{ key: 'a', value: 1 }, { key: 'c', value: 3 }, { key: 'd', value: 4 }]

keyFind

Finds the first item in a list of objects that matches a specific key value.

const data = [
    { key: "a", value: 1 },
    { key: "b", value: 2 },
    { key: "c", value: 3 },
    { key: "d", value: 4 },
];
 
const found = keyFind(data, "c");
console.log(found);
// => { key: 'c', value: 3 }
 
const notFound = keyFind(data, "e");
console.log(notFound);
// => undefined

keyMember

Checks if unknown object in a list has a specific key-value pair.

const data = [
    { id: 1, name: "John" },
    { id: 2, name: "Jane" },
    { id: 3, name: "Alice" },
];
 
console.log(keyMember(data, "id", 2));
// => true
 
console.log(keyMember(data, "name", "Bob"));
// => false

keySort

Sorts a list of objects based on a specific key.

const data = [
    { id: 3, name: "Alice" },
    { id: 1, name: "John" },
    { id: 2, name: "Jane" },
];
 
const sortedData = keySort(data, "id");
console.log(sortedData);
// => [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }, { id: 3, name: 'Alice' }]

keyStore

Transforms a list of items into an array of key-value tuples where the value is set to a default value for items with a specific key.

interface Person {
    id: number;
    name: string;
}
 
const people: Person[] = [
    { id: 1, name: "Alice" },
    { id: 2, name: "Bob" },
    { id: 3, name: "Charlie" },
];
 
const result = keyStore(people, "name", "Unknown", (person) => person.name);
console.log(result);
// => [[ { id: 1, name: 'Alice' }, 'Unknown' ], [ { id: 2, name: 'Bob' }, 'Unknown' ], [ { id: 3, name: 'Charlie' }, 'Unknown' ]]

keywordListToObject | keywordObjectToList

Converts a keyword list in array format to object format.

popAt

Removes an item at the specified index from a list | Converts a keyword list in object format to array format.

const options = [
    ["exit_on_close", true],
    ["active", "once"],
    ["packet_size", 1024],
];
 
// Converting the keyword list to an object
const optionsObject = keywordListToObject(options);
console.log(optionsObject);
// => { exit_on_close: true, active: 'once', packet_size: 1024 }
 
// Accessing values from the keyword list object
console.log(optionsObject.exit_on_close); // => true
console.log(optionsObject.active); // => 'once'
console.log(optionsObject.packet_size); // => 1024
 
// Modifying values in the keyword list object
optionsObject.active = 'continuous';
console.log(optionsObject.active); // => 'continuous'
 
// Converting the keyword list object back to an array
const updatedOptionsList = keywordObjectToList(optionsObject);
console.log(updatedOptionsList); // => [ [ 'exit_on_close', true ], [ 'active', 'continuous' ], [ 'packet_size', 1024 ] ]
const list = [1, 2, 3, 4, 5];
const popped = popAt(list, 2);
console.log(popped);
// => [1, 2, 4, 5]

updateAt

Updates an item at the specified index in a list with a new value.

const list = ["apple", "banana", "cherry"];
const updated = updateAt(list, 1, "orange");
console.log(updated);
// => ['apple', 'orange', 'cherry']

wrap

Wraps a value in an array.

const wrapped = wrap("Hello");
console.log(wrapped);
// => ['Hello']