# ListToMap(A, B)ΒΆ

list.spad line 365 [edit on github]

A: SetCategory

B: Type

ListToMap allows mappings to be described by a pair of lists of equal lengths. The image of an element `x`

, which appears in position `n`

in the first list, is then the `n`

th element of the second list. A default value or default function can be specified to be used when `x`

does not appear in the first list. In the absence of defaults, an error will occur in that case.

- match: (List A, List B) -> A -> B
`match(la, lb)`

creates a map with no default source or target values defined by lists`la`

and`lb`

of equal length. The target of a source value`x`

in`la`

is the value`y`

with the same index in`lb`

. Error: if`la`

and`lb`

are not of equal length. Note: when this map is applied, an error occurs when applied to a value missing from`la`

.

- match: (List A, List B, A -> B) -> A -> B
`match(la, lb, f)`

creates a map defined by lists`la`

and`lb`

of equal length. The target of a source value`x`

in`la`

is the value`y`

with the same index in`lb`

. Argument`f`

is used as the function to call when the given function argument is not in`la`

. The value returned is`f`

applied to that argument.

- match: (List A, List B, A) -> B
`match(la, lb, a)`

creates a map defined by lists`la`

and`lb`

of equal length, where`a`

is used as the default source value if the given one is not in`la`

. The target of a source value`x`

in`la`

is the value`y`

with the same index in`lb`

. Error: if`la`

and`lb`

are not of equal length.

- match: (List A, List B, A, A -> B) -> B
`match(la, lb, a, f)`

creates a map defined by lists`la`

and`lb`

of equal length, and applies this map to a. The target of a source value`x`

in`la`

is the value`y`

with the same index in`lb`

. Argument`f`

is a default function to call if a is not in`la`

. The value returned is then obtained by applying`f`

to argument a.

- match: (List A, List B, A, B) -> B
`match(la, lb, a, b)`

creates a map defined by lists`la`

and`lb`

of equal length, and applies this map to a. The target of a source value`x`

in`la`

is the value`y`

with the same index in`lb`

. Argument`b`

is the default target value if a is not in`la`

. Error: if`la`

and`lb`

are not of equal length.

- match: (List A, List B, B) -> A -> B
`match(la, lb, b)`

creates a map defined by lists`la`

and`lb`

of equal length, where`b`

is used as the default target value if the given function argument is not in`la`

. The target of a source value`x`

in`la`

is the value`y`

with the same index in`lb`

. Error: if`la`

and`lb`

are not of equal length.