All help topics · Link to this topic
Showing help on 'slice()'
Syntax: slice(LIST <alist> [, INT | LIST | STR <index>, ANY <default map value>]) => LISTReturn the <index>-th elements of <alist>. By default, index will be 1. If index is a list of integers, the returned list will have those elements from <alist>. This is the built-in equivalent of LambdaCore's $list_utils:slice verb.
If <alist> is a list of maps, index can be a string indicating a key to return from each map in <alist>.
If <default map value> is specified, any maps not containing the key <index> will have <default map value> returned in their place. This is useful in situations where you need to maintain consistency with a list index and can't have gaps in your return list.
Examples:
>slice({{"z", 1}, {"y", 2}, {"x",5}}, 2) => {1, 2, 5}.
>slice({{"z", 1, 3}, {"y", 2, 4}}, {2, 1}) => {{1, "z"}, {2, "y"}}
>;slice({["a" -> 1, "b" -> 2], ["a" -> 5, "b" -> 6]}, "a") => {1, 5}
>;slice({["a" -> 1, "b" -> 2], ["a" -> 5, "b" -> 6], ["b" -> 8]}, "a", 0) => {1, 5, 0}