Skip to main content
Version: 2.9.x

lists

Functions for lists

Macros and Functions

every

Check if every item of arr passes function f.

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

Example usage (generated):

load("@aspect_bazel_lib//lib:lists.bzl", "every")

every(
# Function to execute on every item
f = None,
# List to iterate over
arr = None,
)

f

Required.

Function to execute on every item

arr

Required.

List to iterate over

filter

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"]

Example usage (generated):

load("@aspect_bazel_lib//lib:lists.bzl", "filter")

filter(
# Function to execute on every item
f = None,
# List to iterate over
arr = None,
)

f

Required.

Function to execute on every item

arr

Required.

List to iterate over

find

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. Furthermore find does not fail if no item passes f. In this case (-1, None) is returned.

Example usage (generated):

load("@aspect_bazel_lib//lib:lists.bzl", "find")

find(
# Function to execute on every item
f = None,
# List to iterate over
arr = None,
)

f

Required.

Function to execute on every item

arr

Required.

List to iterate over

map

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]

Example usage (generated):

load("@aspect_bazel_lib//lib:lists.bzl", "map")

map(
# Function to execute on every item
f = None,
# List to iterate over
arr = None,
)

f

Required.

Function to execute on every item

arr

Required.

List to iterate over

once

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

Example usage (generated):

load("@aspect_bazel_lib//lib:lists.bzl", "once")

once(
# Function to execute on every item
f = None,
# List to iterate over
arr = None,
)

f

Required.

Function to execute on every item

arr

Required.

List to iterate over

pick

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.

Example usage (generated):

load("@aspect_bazel_lib//lib:lists.bzl", "pick")

pick(
# Function to execute on every item
f = None,
# List to iterate over
arr = None,
)

f

Required.

Function to execute on every item

arr

Required.

List to iterate over

some

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

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

Example usage (generated):

load("@aspect_bazel_lib//lib:lists.bzl", "some")

some(
# Function to execute on every item
f = None,
# List to iterate over
arr = None,
)

f

Required.

Function to execute on every item

arr

Required.

List to iterate over

unique

Return a new list with unique items in it.

Example: unique(["foo", "bar", "foo", "baz"]) // ["foo", "bar", "baz"]

Example usage (generated):

load("@aspect_bazel_lib//lib:lists.bzl", "unique")

unique(
# List to iterate over
arr = None,
)

arr

Required.

List to iterate over