February 2019
Beginner to intermediate
180 pages
4h 4m
English
The take function accepts a list and a length and returns a subset of the list starting from the head of the list with length equal to the requested length. Since the requested length of the subset may exceed the original list's length, the result is wrapped in an option. Its type is as follows:
(Belt.List.t('a), int) => option(Belt.List.t('a))
We can take the first two items from our shuffled list, like so:
let list = Belt.List.(makeBy(10, i => i)->shuffle->take(2));
Read now
Unlock full access