package sherlodoc

  1. Overview
  2. Docs
Search engine for OCaml documentation

Install

Dune Dependency

Authors

Maintainers

Sources

odoc-3.1.0.tbz
sha256=355b3cfff4934903cbaed8b51ce35e333e8609932d230294200a9f2d42ffa914
sha512=f78318d0a16164a9cd16ee02f611c2e00d32b772fe38e992d6db6ec94b1c00cd9c377fbfe64031b8f245e57b2f3aac9364108327e7f1693533ddcff94c476e05

doc/src/sherlodoc.query/io.ml.html

Source file io.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module type S = sig
  (* avoids a dependency on lwt for sherlodoc.js *)

  type 'a t

  val return : 'a -> 'a t
  val map : 'a t -> ('a -> 'b) -> 'b t
  val bind : 'a t -> ('a -> 'b t) -> 'b t
end

module Seq (Io : S) = struct
  type 'a t = unit -> 'a node Io.t

  and 'a node =
    | Nil
    | Cons of 'a * 'a t

  let rec of_seq s () =
    match s () with
    | Seq.Nil -> Io.return Nil
    | Cons (x, xs) -> Io.return (Cons (x, of_seq xs))

  let rec take n xs () =
    if n = 0
    then Io.return Nil
    else begin
      Io.map (xs ())
      @@ function
      | Nil -> Nil
      | Cons (x, xs) -> Cons (x, take (n - 1) xs)
    end

  let rec to_list acc s =
    Io.bind (s ())
    @@ function
    | Nil -> Io.return (List.rev acc)
    | Cons (x, xs) -> to_list (x :: acc) xs

  let to_list s = to_list [] s
end
OCaml

Innovation. Community. Security.