Functions for lists

every


every(<a href="#every-f">f</a>, <a href="#every-arr">arr</a>)

Check if every item of arr passes function f.

Example: every(lambda i: i.endswith(".js"), ["app.js", "lib.js"]) // True

PARAMETERS

NameDescriptionDefault Value
fFunction to execute on every itemnone
arrList to iterate overnone

RETURNS

True or False

filter


filter(<a href="#filter-f">f</a>, <a href="#filter-arr">arr</a>)

Filter a list arr by applying a function f to each item.

Example: filter(lambda i: i.endswith(".js"), ["app.ts", "app.js", "lib.ts", "lib.js"]) // ["app.js", "lib.js"]

PARAMETERS

NameDescriptionDefault Value
fFunction to execute on every itemnone
arrList to iterate overnone

RETURNS

A new list containing items that passed the filter function.

find


find(<a href="#find-f">f</a>, <a href="#find-arr">arr</a>)

Find a particular item from list arr by a given function f.

Unlike pick, the find method returns a tuple of the index and the value of first item passing by f. Furhermore find does not fail if no item passes f. In this case (-1, None) is returned.

PARAMETERS

NameDescriptionDefault Value
fFunction to execute on every itemnone
arrList to iterate overnone

RETURNS

Tuple (index, item)

map


map(<a href="#map-f">f</a>, <a href="#map-arr">arr</a>)

Apply a function f with each item of arr and return a new list.

Example: map(lambda i: i*2, [1, 2, 3]) // [2, 4, 6]

PARAMETERS

NameDescriptionDefault Value
fFunction to execute on every itemnone
arrList to iterate overnone

RETURNS

A new list with all mapped items.

once


once(<a href="#once-f">f</a>, <a href="#once-arr">arr</a>)

Check if exactly one item in list arr passes the given function f.

PARAMETERS

NameDescriptionDefault Value
fFunction to execute on every itemnone
arrList to iterate overnone

RETURNS

True or False

pick


pick(<a href="#pick-f">f</a>, <a href="#pick-arr">arr</a>)

Pick a particular item in list arr by a given function f.

Unlike filter, the pick method returns the first item found by f. If no item has passed f, the function will fail.

PARAMETERS

NameDescriptionDefault Value
fFunction to execute on every itemnone
arrList to iterate overnone

RETURNS

item

some


some(<a href="#some-f">f</a>, <a href="#some-arr">arr</a>)

Check if at least one item of arr passes function f.

Example: some(lambda i: i.endswith(".js"), ["app.js", "lib.ts"]) // True

PARAMETERS

NameDescriptionDefault Value
fFunction to execute on every itemnone
arrList to iterate overnone

RETURNS

True or False