From 055c743c55bde27f4475d3434c26d8383c0c3ea1 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Thu, 11 Jan 2024 19:31:31 +0100 Subject: bulk: add PoC of vim-like modular editor --- lib/util.ml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 lib/util.ml (limited to 'lib/util.ml') 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 @@ +(** 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 -- cgit v1.2.3