Skip to content

Instantly share code, notes, and snippets.

@ccorcos
Created March 28, 2017 17:49
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/e61ae52f7b480a219e3e861d52f8c4d8 to your computer and use it in GitHub Desktop.
Save ccorcos/e61ae52f7b480a219e3e861d52f8c4d8 to your computer and use it in GitHub Desktop.
let rec firstN n l =>
if (n === 0 || List.length l === 0) {
[]
} else {
let h = List.hd l;
let t = List.tl l;
List.append [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