diff options
| author | Federico Igne <undyamon@disroot.org> | 2024-01-11 19:31:31 +0100 |
|---|---|---|
| committer | Federico Igne <undyamon@disroot.org> | 2024-01-11 19:31:31 +0100 |
| commit | 055c743c55bde27f4475d3434c26d8383c0c3ea1 (patch) | |
| tree | aabf2173a9995f5795da86d5676181b62fee0e9e /lib/util.ml | |
| parent | 416c56656af65d656f637dc8c8fdb62d0ba03e29 (diff) | |
| download | sandy-055c743c55bde27f4475d3434c26d8383c0c3ea1.tar.gz sandy-055c743c55bde27f4475d3434c26d8383c0c3ea1.zip | |
bulk: add PoC of vim-like modular editor
Diffstat (limited to 'lib/util.ml')
| -rw-r--r-- | lib/util.ml | 26 |
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 | |||
| 3 | open 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]. *) | ||
| 11 | let ( &> ) 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. *) | ||
| 17 | let 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 | ||
