package inquire

  1. Overview
  2. Docs
An OCaml library to create beautiful interactive CLIs

Install

Dune Dependency

Authors

Maintainers

Sources

inquire-0.2.1.tbz
sha256=0b88d89e24d4cbc0560a7c8d8ec51388990e1b27f24685029997afa52a7c720f
sha512=8b62860a8d15e41528a404a6f1b9968c3d79755607b5ea319af2e3e45516e672a785361d278279910928db4054e1800e87bcee0210ff3eabfb330713b368c827

doc/src/inquire.zed/zed_utils.ml.html

Source file zed_utils.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
(*
 * zed_utils.ml
 * -----------
 * Copyright : (c) 2019, ZAN DoYe <zandoye@gmail.com>
 * Licence   : BSD3
 *
 * This file is a part of Zed, an editor engine.
 *)


let array_rev a=
  let len= Array.length a - 1 in
  Array.init len (fun i-> a.(len-i))

let rec list_compare ?(compare=compare) l1 l2=
  match l1, l2 with
  | [], []-> 0
  | [], _-> -1
  | _, []-> 1
  | h1::t1, h2::t2->
    match compare h1 h2 with
    | 0-> list_compare ~compare t1 t2
    | _ as r-> r

let array_compare ?(compare=compare) a1 a2=
  let len1= Array.length a1
  and len2= Array.length a2 in
  let rec compare_aux pos=
    let remain1= len1 - pos
    and remain2= len2 - pos in
    if remain1 <= 0 && remain2 <= 0 then 0
    else if remain1 <= 0 && remain2 > 0 then -1
    else if remain1 > 0 && remain2 <= 0 then 1
    else match compare a1.(pos) a2.(pos) with
      | 0-> compare_aux (pos + 1)
      | _ as r-> r
  in
  compare_aux 0

OCaml

Innovation. Community. Security.