Skip to content

Commit

Permalink
Merge pull request #6 from seliopou/each
Browse files Browse the repository at this point in the history
each: add each operator
  • Loading branch information
seliopou committed Oct 8, 2015
2 parents 110b96b + a1a8586 commit 4677b39
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/d3.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ let exit : ('a, 'a) t = thunk_call "exit"

let filter f = const_call "filter" (mb (fun this d i () -> Js.bool (f this d i)))
let sort f = const_call "sort" f
let each f = const_call "each" (mb (fun this d i () -> (f this d i)))

let str f name x = f name (fun _ _ _ -> x)
let int f name x = str f name (string_of_int x)
Expand Down
7 changes: 6 additions & 1 deletion lib/d3.mli
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,17 @@ val filter : ('a, bool) fn -> ('a, 'a) t
{{:https://github.com/mbostock/d3/wiki/Selections#filter}D3.js docs} *)

val sort : ('a -> 'a -> int) -> ('a, 'a) t
val sort : ('a -> 'a -> int) -> ('a, 'a) t
(** [sort f] sorts the elements in the current selection according to the
comparator function, and then re-inserts the document elements to match.
{{:https://github.com/mbostock/d3/wiki/Selections#sort}D3.js docs} *)

val each : ('a, unit) fn -> ('a, 'a) t
(** [each f] invokes [f] for each element in the current selection.
{{:https://github.com/mbostock/d3/wiki/Selections#each}D3.js docs} *)

(** {2 Composition operators} *)

val (|.) : ('a, 'b) t -> ('b, 'c) t -> ('a, 'c) t
Expand Down

0 comments on commit 4677b39

Please sign in to comment.