mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-09 04:17:56 -04:00
feat emitter: add flat_map
This commit is contained in:
parent
8640db6a8c
commit
a98a1aeb3f
1 changed files with 12 additions and 2 deletions
|
|
@ -33,11 +33,21 @@ let[@inline] closed self : bool = self.closed ()
|
||||||
|
|
||||||
let[@inline] flush_and_close (self : _ t) : unit = self.flush_and_close ()
|
let[@inline] flush_and_close (self : _ t) : unit = self.flush_and_close ()
|
||||||
|
|
||||||
(** [map f emitter] returns a new emitter that applies [f] to signals before
|
(** [map f emitter] returns a new emitter that applies [f] to signals item-wise
|
||||||
passing them to [emitter] *)
|
before passing them to [emitter] *)
|
||||||
let map (f : 'a -> 'b) (self : 'b t) : 'a t =
|
let map (f : 'a -> 'b) (self : 'b t) : 'a t =
|
||||||
{ self with emit = (fun l -> self.emit (List.map f l)) }
|
{ self with emit = (fun l -> self.emit (List.map f l)) }
|
||||||
|
|
||||||
|
(** [map_l f emitter] applies [f] to incoming lists of signals, and emits the
|
||||||
|
resulting list (if non empty) *)
|
||||||
|
let flat_map (f : 'a list -> 'b list) (self : 'b t) : 'a t =
|
||||||
|
let emit l =
|
||||||
|
match f l with
|
||||||
|
| [] -> ()
|
||||||
|
| fl -> self.emit fl
|
||||||
|
in
|
||||||
|
{ self with emit }
|
||||||
|
|
||||||
(** [tap f e] is like [e], but every signal is passed to [f] *)
|
(** [tap f e] is like [e], but every signal is passed to [f] *)
|
||||||
let tap (f : 'a -> unit) (self : 'a t) : 'a t =
|
let tap (f : 'a -> unit) (self : 'a t) : 'a t =
|
||||||
let emit l =
|
let emit l =
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue