summaryrefslogtreecommitdiff
path: root/lib/util.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/util.ml')
-rw-r--r--lib/util.ml26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/util.ml b/lib/util.ml
new file mode 100644
index 0000000..9ad3b59
--- /dev/null
+++ b/lib/util.ml
@@ -0,0 +1,26 @@
1(** The infamous [Util] module. A graveyard of broken expressions. *)
2
3open Base
4
5(** [f &> g] composes [g] with [f] to obrain [fun x -> g (f x)];
6 in other words, it applies [f] {i and then} [g].
7
8 @param f the first funtion to apply.
9 @param g the second function to apply.
10 @return the composition of [g] with [f]. *)
11let ( &> ) f g = Fn.compose g f
12
13(** Turn a sequence of bytes into a sequence.
14
15 @param b the input bytes.
16 @return a sequence of bytes. *)
17let sequence_of_bytes (b : Bytes.t) : char Sequence.t =
18 let open Sequence.Generator in
19 let traverse b =
20 let len = Bytes.length b in
21 let rec loop i _ =
22 if i >= len then return () else yield (Bytes.get b i) >>= loop (i + 1)
23 in
24 loop 0 ()
25 in
26 traverse b |> run