A lightweight reactive document library.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

39 lines
1.1 KiB

  1. type 'a monoid = 'a * ('a -> 'a -> 'a)
  2. (** A monoid, defined by a default element and an associative operation *)
  3. val lift_monoid : 'a monoid -> 'a Lwd.t monoid
  4. (** Use a monoid inside [Lwd] *)
  5. (** {1 List reduction functions}
  6. All reductions are balanced, relying on operator associativity.
  7. [fold_left] would compute a chain like:
  8. [fold f [a; b; c; d] = f a (f b (f c d)]
  9. [reduce] uses tree-shaped computations like:
  10. [reduce f [a; b; c; d] = f (f a b) (f c d)]
  11. The depth of the computation grows in O(log n) where n is the length of the
  12. input sequence.
  13. *)
  14. val pack : 'a monoid -> 'a Lwd.t list -> 'a Lwd.t
  15. (** Reduce a list of elements in [Lwd] monad *)
  16. val pack_seq : 'a monoid -> 'a Lwd.t Seq.t -> 'a Lwd.t
  17. (** Reduce an (OCaml) [Seq.t] with a monoid *)
  18. val reduce : 'a monoid -> 'a list -> 'a
  19. (** Reduce a list with a monoid **)
  20. val map_reduce : ('a -> 'b) -> 'b monoid -> 'a list -> 'b
  21. (** Map and reduce a list with a monoid **)
  22. (** {1 Other Lwd list functions} *)
  23. val map_l : ('a -> 'b Lwd.t) -> 'a list -> 'b list Lwd.t
  24. val flatten_l : 'a Lwd.t list -> 'a list Lwd.t
  25. (** Commute [Lwd] and [list] *)