Skip to content

Instantly share code, notes, and snippets.

@ccorcos
Created March 28, 2017 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccorcos/6e3d1b9c7ad3b00de2af9dc5f697b4cf to your computer and use it in GitHub Desktop.
Save ccorcos/6e3d1b9c7ad3b00de2af9dc5f697b4cf to your computer and use it in GitHub Desktop.
let rec firstN n l =>
switch (n, l) {
| (0, _) => []
| (_, []) => []
| (n, [h, ...t]) => [h, ...firstN (n - 1) t]
};
firstN 2 [1, 2, 3, 4, 5]; /* => list int: [1, 2] */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment