feat: add infix operators to String

close #315
This commit is contained in:
Simon Cruanes 2020-07-28 17:34:59 -04:00
parent 39e0ad2395
commit 211cd5863b
3 changed files with 72 additions and 0 deletions

View file

@ -3,6 +3,10 @@
(** {1 Basic String Utils} *) (** {1 Basic String Utils} *)
(*$inject
open CCShims_.Stdlib
*)
open CCShims_ open CCShims_
type 'a iter = ('a -> unit) -> unit type 'a iter = ('a -> unit) -> unit
@ -1053,6 +1057,22 @@ let pp_buf buf s =
let pp fmt s = let pp fmt s =
Format.fprintf fmt "\"%s\"" s Format.fprintf fmt "\"%s\"" s
module Infix = struct
let (=) = equal
let (<>) a b = not (equal a b)
let (>) : t -> t -> bool = CCShims_.Stdlib.(>)
let (>=) : t -> t -> bool = CCShims_.Stdlib.(>=)
let (<) : t -> t -> bool = CCShims_.Stdlib.(<)
let (<=) : t -> t -> bool = CCShims_.Stdlib.(<=)
end
include Infix
(*$T
"ab" < "abc"
"123" < "14"
*)
(* test consistency of interfaces *) (* test consistency of interfaces *)
(*$inject (*$inject
module type L = module type of CCString module type L = module type of CCString

View file

@ -417,3 +417,29 @@ val edit_distance : ?cutoff:int -> string -> string -> int
and on the result. (since 3.0). This is useful if you just want to and on the result. (since 3.0). This is useful if you just want to
check whether the edit distance is less or equal than 2 (use cutoff of 3). check whether the edit distance is less or equal than 2 (use cutoff of 3).
*) *)
(** {2 Infix operators}
@since NEXT_RELEASE *)
module Infix : sig
val (=) : t -> t -> bool
(** @since NEXT_RELEASE *)
val (<>) : t -> t -> bool
(** @since NEXT_RELEASE *)
val (<) : t -> t -> bool
(** @since NEXT_RELEASE *)
val (<=) : t -> t -> bool
(** @since NEXT_RELEASE *)
val (>=) : t -> t -> bool
(** @since NEXT_RELEASE *)
val (>) : t -> t -> bool
(** @since NEXT_RELEASE *)
end
include module type of Infix

View file

@ -436,3 +436,29 @@ val edit_distance : ?cutoff:int -> string -> string -> int
and on the result. (since 3.0). This is useful if you just want to and on the result. (since 3.0). This is useful if you just want to
check whether the edit distance is less or equal than 2 (use cutoff of 3). check whether the edit distance is less or equal than 2 (use cutoff of 3).
*) *)
(** {2 Infix operators}
@since NEXT_RELEASE *)
module Infix : sig
val (=) : t -> t -> bool
(** @since NEXT_RELEASE *)
val (<>) : t -> t -> bool
(** @since NEXT_RELEASE *)
val (<) : t -> t -> bool
(** @since NEXT_RELEASE *)
val (<=) : t -> t -> bool
(** @since NEXT_RELEASE *)
val (>=) : t -> t -> bool
(** @since NEXT_RELEASE *)
val (>) : t -> t -> bool
(** @since NEXT_RELEASE *)
end
include module type of Infix