-
Notifications
You must be signed in to change notification settings - Fork 96
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
5 changed files
with
52 additions
and
51 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
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,29 @@ | ||
include List | ||
|
||
let rec concat_map ?sep ~f = function | ||
| [] -> [] | ||
| [ x ] -> f x | ||
| x :: xs -> ( | ||
let hd = f x in | ||
let tl = concat_map ?sep ~f xs in | ||
match sep with None -> hd @ tl | Some sep -> hd @ (sep :: tl)) | ||
|
||
let rec filter_map acc f = function | ||
| hd :: tl -> | ||
let acc = match f hd with Some x -> x :: acc | None -> acc in | ||
filter_map acc f tl | ||
| [] -> List.rev acc | ||
|
||
let filter_map f x = filter_map [] f x | ||
|
||
(** @raise [Failure] if the list is empty. *) | ||
let rec last = function | ||
| [] -> failwith "Odoc_utils.List.last" | ||
| [ x ] -> x | ||
| _ :: tl -> last tl | ||
|
||
(* From ocaml/ocaml *) | ||
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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module List = Odoc_list | ||
|
||
type 'a t = { node : 'a; children : 'a forest } | ||
and 'a forest = 'a t list | ||
|
||
|