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 listsla
andlb
of equal length. The target of a source valuex
inla
is the valuey
with the same index inlb
. Error: ifla
andlb
are not of equal length. Note: when this map is applied, an error occurs when applied to a value missing fromla
.
- match: (List A, List B, A -> B) -> A -> B
match(la, lb, f)
creates a map defined by listsla
andlb
of equal length. The target of a source valuex
inla
is the valuey
with the same index inlb
. Argumentf
is used as the function to call when the given function argument is not inla
. The value returned isf
applied to that argument.
- match: (List A, List B, A) -> B
match(la, lb, a)
creates a map defined by listsla
andlb
of equal length, wherea
is used as the default source value if the given one is not inla
. The target of a source valuex
inla
is the valuey
with the same index inlb
. Error: ifla
andlb
are not of equal length.
- match: (List A, List B, A, A -> B) -> B
match(la, lb, a, f)
creates a map defined by listsla
andlb
of equal length, and applies this map to a. The target of a source valuex
inla
is the valuey
with the same index inlb
. Argumentf
is a default function to call if a is not inla
. The value returned is then obtained by applyingf
to argument a.
- match: (List A, List B, A, B) -> B
match(la, lb, a, b)
creates a map defined by listsla
andlb
of equal length, and applies this map to a. The target of a source valuex
inla
is the valuey
with the same index inlb
. Argumentb
is the default target value if a is not inla
. Error: ifla
andlb
are not of equal length.
- match: (List A, List B, B) -> A -> B
match(la, lb, b)
creates a map defined by listsla
andlb
of equal length, whereb
is used as the default target value if the given function argument is not inla
. The target of a source valuex
inla
is the valuey
with the same index inlb
. Error: ifla
andlb
are not of equal length.