Created
April 5, 2021 00:55
-
-
Save nsmmrs/9772edcb7813ee326e5dbd0dd849e48f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let filter_take ~f:valid n list = | |
let rec take_from ?(taken = []) ?(n_taken = 0) list = | |
if n_taken = n then taken | |
else | |
match list with | |
| [] -> taken | |
| e :: remaining -> | |
let taken, n_taken = | |
if valid e then (e :: taken, n_taken + 1) else (taken, n_taken) | |
in | |
take_from remaining ~taken ~n_taken | |
in | |
take_from list |> List.rev |
Author
nsmmrs
commented
Apr 5, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment