treelist_  util
List.index_  of
List.index_  where
List.splitf
List.append_  all
List.flatten
List.cartesian_  product
List.cartesian_  product_  all
8.16.0.4

treelist_util🔗ℹ

 import: treelist_util package: treelist-util

List operations matching racket/list that aren’t in Rhombus List.

function

fun List.index_of(l :: List, v :: Any) :: maybe(NonnegInt)

Returns the index of the first element in l that is == to v. If no such element is found, the result is #false.

> List.index_of([2, 4, 5, 8], 5)

2

> List.index_of([2, 4, 5, 8], 6)

#false

Returns the index of the first element in l where applying pred to the element produces a true value. If no such element is found, the result is #false.

> List.index_where([2, 4, 5, 8], is_odd)

2

> List.index_where([2, 4, 5, 8], is_negative)

#false

function

fun List.splitf(l :: List, pred :: Function.of_arity(1)) :: values(List, List)

Splits l into 2 lists returned as values. The first list contains elements taken successivly from l as long as they satisfy pred. The second list the rest of the elements of l, from the first element not satisfying pred and onward.

> List.splitf([2, 4, 5, 8], is_even)

[2, 4]

[5, 8]

Appends elements of a list of lists together into one list, leaving any further nested lists alone.

> List.append_all([["a", "b"], ["c", ["d"], "e"], []])

["a", "b", "c", ["d"], "e"]

function

fun List.flatten(v :: Any) :: List

Flattens a tree of nested lists into a single list.

> List.flatten([["a"], "b", ["c", ["d", "e"], []]])

["a", "b", "c", "d", "e"]

> List.flatten("a")

["a"]

Computes the n-ary cartesian product of the given lists.

> List.cartesian_product([1, 2, 3], ["a", "b", "c"])

[

  [1, "a"],

  [1, "b"],

  [1, "c"],

  [2, "a"],

  [2, "b"],

  [2, "c"],

  [3, "a"],

  [3, "b"],

  [3, "c"]

]

> List.cartesian_product_all([[4, 5, 6], ["d", "e", "f"], [#true, #false]])

[

  [4, "d", #true],

  [4, "d", #false],

  [4, "e", #true],

  [4, "e", #false],

  [4, "f", #true],

  [4, "f", #false],

  [5, "d", #true],

  [5, "d", #false],

  [5, "e", #true],

  [5, "e", #false],

  [5, "f", #true],

  [5, "f", #false],

  [6, "d", #true],

  [6, "d", #false],

  [6, "e", #true],

  [6, "e", #false],

  [6, "f", #true],

  [6, "f", #false]

]