-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
22 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
let rec find_map f = function | ||
| [] -> None | ||
| x :: l -> ( | ||
match f x with | ||
| Some _ as result -> result | ||
| None -> find_map f l | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
open String | ||
|
||
let ends_with ~suffix s = | ||
let len_s = length s | ||
and len_suf = length suffix in | ||
let diff = len_s - len_suf in | ||
let rec aux i = | ||
if i = len_suf then true | ||
else if unsafe_get s (diff + i) <> unsafe_get suffix i then false | ||
else aux (i + 1) | ||
in diff >= 0 && aux 0 |