Navigation
Synopsis Get number of elements from the head of a list.
Function list[&T] take(int n, list[&T] lst)
Usage import List;
Description Get n elements (or size(lst) elements if size(lst) < n) from the head of the list. See drop to remove elements from the head of a list.
Examples
rascal>import List;
ok
rascal>take(2, [3, 1, 4, 5]);
list[int]: [3,1]
rascal>take(6, [3, 1, 4, 5]);
list[int]: [3,1,4,5]
rascal>take(2, ["zebra", "elephant", "snake", "owl"]);
list[str]: ["zebra","elephant"]

Questions
Question [1]. Computing take(M, L) of a list with N (N > M) elements returns a list with




Question [2].
The type of take(2, [-12, 7, -8, 11]) is

Question [3].
take(1, [3, 3, 7, -19]) == 



Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.