-
Notifications
You must be signed in to change notification settings - Fork 31
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
17 changed files
with
925 additions
and
71 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
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
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,58 @@ | ||
module Symbol = [%js: | ||
[@@@js.scope "Symbol"] | ||
type t = private Ojs.t | ||
|
||
val iterator : t [@@js.global] | ||
|
||
val get: Ojs.t -> t -> Ojs.t | ||
] | ||
|
||
include [%js: | ||
|
||
type next = { | ||
value: Ojs.t; | ||
is_done: bool; [@js "done"] | ||
} | ||
|
||
type t = private Ojs.t | ||
val t_of_js: Ojs.t -> t | ||
val t_to_js: t -> Ojs.t | ||
|
||
val next: t -> next [@js.call] | ||
|
||
] | ||
|
||
let iterator o : t option = | ||
match | ||
[%js.to: (unit -> t) option] | ||
(Symbol.get o Symbol.iterator) | ||
with | ||
| None -> None | ||
| Some f -> Some (f ()) | ||
|
||
let until f it = | ||
while | ||
let next = next it in | ||
not (next.is_done || f next.value) | ||
do () done | ||
|
||
module Iterable (X : Ojs.T) (K: Ojs.T) = struct | ||
|
||
let until f x = | ||
match iterator (X.t_to_js x) with | ||
| None -> () | ||
| Some it -> | ||
until (fun k -> f (K.t_of_js k)) it | ||
|
||
let iter f x = | ||
until (fun k -> f k; false) x | ||
|
||
let fold f x acc = | ||
let acc = ref acc in | ||
iter | ||
(fun k -> | ||
acc := f k !acc | ||
) x; | ||
!acc | ||
|
||
end |
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,13 @@ | ||
type t = private Ojs.t | ||
val t_to_js: t -> Ojs.t | ||
val t_of_js: Ojs.t -> t | ||
|
||
val iterator: Ojs.t -> t option | ||
val until: (Ojs.t -> bool) -> t -> unit | ||
|
||
module Iterable (X : Ojs.T) (K : Ojs.T): | ||
sig | ||
val until : (K.t -> bool) -> X.t -> unit | ||
val iter : (K.t -> unit) -> X.t -> unit | ||
val fold : (K.t -> 'a -> 'a) -> X.t -> 'a -> 'a | ||
end |
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
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
Oops, something went wrong.