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.
 
 

103 lines
3.2 KiB

  1. (** {0 Table manipulation}
  2. [Lwd_table] is an ordered collection with an impure interface.
  3. It is designed to be efficient in an interactive setting.
  4. The interface mimics the one of a doubly-linked lists: from a node, called
  5. row, you can iterate backward and forward, insert and delete other nodes,
  6. and change the value it is bound to.
  7. The sequence of nodes can be observed by map/reduce operations, that will
  8. be recomputed efficiently when sequence changes.
  9. *)
  10. type 'a t
  11. type 'a row
  12. (** The type of tables *)
  13. val make : unit -> 'a t
  14. (** Create a new table *)
  15. (** {1 Inserting rows} *)
  16. val prepend : ?set:'a -> 'a t -> 'a row
  17. (** Insert and return a new row at the start of a table.
  18. It can be optionnally initialized to the value of [set]. *)
  19. val append : ?set:'a -> 'a t -> 'a row
  20. (** Insert and return a new row at the end of a table.
  21. It can be optionnally initialized to the value of [set]. *)
  22. val prepend' : 'a t -> 'a -> unit
  23. (* Insert a new initialized row at start of a table *)
  24. val append' : 'a t -> 'a -> unit
  25. (* Insert a new initialized row at end of a table *)
  26. val before : ?set:'a -> 'a row -> 'a row
  27. (** Insert and return a new row just before an existing row.
  28. It can be optionnally initialized to the value of [set].
  29. If the input row is unbound ([is_bound] returns false), the returned row is
  30. too.
  31. *)
  32. val after : ?set:'a -> 'a row -> 'a row
  33. (** Insert and return a new row just after an existing row.
  34. It can be optionnally initialized to the value of [set].
  35. If the input row is unbound ([is_bound] returns false), the returned row is
  36. too.
  37. *)
  38. (** {1 Iterating over rows} *)
  39. val first : 'a t -> 'a row option
  40. (** Returns the first row of a table, or [None] if the table is empty *)
  41. val last : 'a t -> 'a row option
  42. (** Returns the last row of a table, or [None] if the table is empty *)
  43. val next : 'a row -> 'a row option
  44. (** Returns the row next to another one, or [None] if the input row is unbound
  45. or is the last row *)
  46. val prev : 'a row -> 'a row option
  47. (** Returns the row just before another one, or [None] if the input row is
  48. unbound or is the first row *)
  49. (** {1 Accessing and changing row contents} *)
  50. val get : 'a row -> 'a option
  51. (** Get the value associated with a row, if any, or [None] if the row is
  52. unbound *)
  53. val set : 'a row -> 'a -> unit
  54. (** Set the value associated with a row, or do nothing if the row is unbound *)
  55. val unset : 'a row -> unit
  56. (** Unset the value associated with a row *)
  57. (** {1 Removing rows} *)
  58. val is_bound : 'a row -> bool
  59. (** Returns [true] iff the row is bound in a table (it has not beem [remove]d
  60. yet, the table has not been [clear]ed) *)
  61. val remove : 'a row -> unit
  62. (** [remove] a row from its table, [is_bound] will be [true] after that *)
  63. val clear : 'a t -> unit
  64. (** Remove all rows from a table *)
  65. (** {1 Observing table contents} *)
  66. val reduce : 'a Lwd_utils.monoid -> 'a t -> 'a Lwd.t
  67. (** Observe the content of a table by reducing it with a monoid *)
  68. val map_reduce : ('a row -> 'a -> 'b) -> 'b Lwd_utils.monoid -> 'a t -> 'b Lwd.t
  69. (** Observe the content of a table by mapping and reducing it *)
  70. val iter : ('a -> unit) -> 'a t -> unit
  71. (** Immediate, non reactive, iteration over elements of a table *)