summaryrefslogtreecommitdiff
path: root/lib/util.ml
blob: 9ad3b59c35c9f5ea27d6d6c5f24b044f01155ced (plain) (blame)
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
(** The infamous [Util] module. A graveyard of broken expressions. *)

open Base

(** [f &> g] composes [g] with [f] to obrain [fun x -> g (f x)];
    in other words, it applies [f] {i and then} [g].

    @param f the first funtion to apply.
    @param g the second function to apply.
    @return the composition of [g] with [f]. *)
let ( &> ) f g = Fn.compose g f

(** Turn a sequence of bytes into a sequence.

    @param b the input bytes.
    @return a sequence of bytes. *)
let sequence_of_bytes (b : Bytes.t) : char Sequence.t =
  let open Sequence.Generator in
  let traverse b =
    let len = Bytes.length b in
    let rec loop i _ =
      if i >= len then return () else yield (Bytes.get b i) >>= loop (i + 1)
    in
    loop 0 ()
  in
  traverse b |> run