Skip to content

408 cleanup #436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

## main
- breaking: CCListLabel.compare and CCListLabel.equal takes the function on the elements as named arguments
- breaking: CCListLabel.init now takes the length as a named arguments to follow the Stdlib
- breaking: invert the argument of CCFun.compose to align it with the Stdlib
- breaking: change the semantic of CCFloat.{min,max} with respect to NaN to follow the Stdlib
- breaking: change the semantic of CCInt.rem with respect to negative number to follow the Stdlib

## 3.15

Expand Down Expand Up @@ -38,6 +43,7 @@

## 3.13

- breaking: bump minimum version of OCaml to 4.08
- breaking: delete containers-thread (which was deprecated)
- breaking: pp: modify `Ext.t` so it takes surrounding value
- breaking: remove CCShims
Expand Down
9 changes: 0 additions & 9 deletions src/core/CCArray.ml
Original file line number Diff line number Diff line change
Expand Up @@ -455,15 +455,6 @@ let pp_i ?(pp_start = fun _ () -> ()) ?(pp_stop = fun _ () -> ())
let to_string ?(sep = ", ") item_to_string a =
Array.to_list a |> List.map item_to_string |> String.concat sep

let to_seq a =
let rec aux i () =
if i >= length a then
Seq.Nil
else
Seq.Cons (a.(i), aux (i + 1))
in
aux 0

let to_iter a k = iter k a

let to_gen a =
Expand Down
8 changes: 0 additions & 8 deletions src/core/CCArray.mli
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,6 @@ val to_iter : 'a t -> 'a iter
in modification of the iterator.
@since 2.8 *)

val to_seq : 'a t -> 'a Seq.t
(** [to_seq a] returns a [Seq.t] of the elements of an array [a].
The input array [a] is shared with the sequence and modification of it will result
in modification of the sequence.
Renamed from [to_std_seq] since 3.0.
@since 3.0
*)

val to_gen : 'a t -> 'a gen
(** [to_gen a] returns a [gen] of the elements of an array [a]. *)

Expand Down
25 changes: 1 addition & 24 deletions src/core/CCArrayLabels.mli
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,6 @@ val fold2 : f:('acc -> 'a -> 'b -> 'acc) -> init:'acc -> 'a t -> 'b t -> 'acc
@raise Invalid_argument if [a] and [b] have distinct lengths.
@since 0.20 *)

val iter2 : f:('a -> 'b -> unit) -> 'a t -> 'b t -> unit
(** [iter2 ~f a b] iterates on the two arrays [a] and [b] stepwise.
It is equivalent to [f a0 b0; …; f a.(length a - 1) b.(length b - 1); ()].

@raise Invalid_argument if [a] and [b] have distinct lengths.
@since 0.20 *)

val shuffle : 'a t -> unit
(** [shuffle a] randomly shuffles the array [a], in place. *)

Expand All @@ -248,14 +241,6 @@ val to_iter : 'a t -> 'a iter
in modification of the iterator.
@since 2.8 *)

val to_seq : 'a t -> 'a Seq.t
(** [to_seq a] returns a [Seq.t] of the elements of an array [a].
The input array [a] is shared with the sequence and modification of it will result
in modification of the sequence.
Renamed from [to_std_seq] since 3.0.
@since 3.0
*)

val to_gen : 'a t -> 'a gen
(** [to_gen a] returns a [gen] of the elements of an array [a]. *)

Expand Down Expand Up @@ -286,14 +271,6 @@ val pp_i :
By defaults [pp_start] and [pp_stop] does nothing and [pp_sep] defaults to
(fun out -> Format.fprintf out ",@ "). *)

val map2 : f:('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
(** [map2 ~f a b] applies function [f] to all elements of [a] and [b],
and builds an array with the results returned by [f]:
[[| f a.(0) b.(0); …; f a.(length a - 1) b.(length b - 1)|]].

@raise Invalid_argument if [a] and [b] have distinct lengths.
@since 0.20 *)

val rev : 'a t -> 'a t
(** [rev a] copies the array [a] and reverses it in place.
@since 0.20 *)
Expand All @@ -308,7 +285,7 @@ val filter_map : f:('a -> 'b option) -> 'a t -> 'b t
element of [a] is discarded. *)

val monoid_product : f:('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
(** [monoid_product ~f a b] passes all combinaisons of tuples from the two arrays [a] and [b]
(** [monoid_product ~f a b] passes all combinaisons of tuples from the two arrays [a] and [b]
to the function [f].
@since 2.8 *)

Expand Down
11 changes: 1 addition & 10 deletions src/core/CCBool.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
(* This file is free software, part of containers. See file "license" for more details. *)

type t = bool

let equal (a : bool) b = Stdlib.( = ) a b
let compare (a : bool) b = Stdlib.compare a b
include Bool

let if_then f x =
if x then
Expand All @@ -17,12 +14,6 @@ let if_then_else f g x =
else
g ()

let to_int (x : bool) : int =
if x then
1
else
0

let of_int x : t = x <> 0

type 'a printer = Format.formatter -> 'a -> unit
Expand Down
13 changes: 2 additions & 11 deletions src/core/CCBool.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

(** Basic Bool functions *)

type t = bool

val compare : t -> t -> int
(** [compare b1 b2] is the total ordering on booleans [b1] and [b2], similar to {!Stdlib.compare}. *)

val equal : t -> t -> bool
(** [equal b1 b2] is [true] if [b1] and [b2] are the same. *)
include module type of Bool
(** @inline *)

val if_then : (unit -> 'a) -> t -> 'a option
(** [if_then f x] is [Some (f ())] if [x] is true and None otherwise.
Expand All @@ -18,10 +13,6 @@ val if_then_else : (unit -> 'a) -> (unit -> 'a) -> t -> 'a
(** [if_then_else f g x] is [f ()] if [x] is true and [g ()] otherwise.
@since 3.13 *)

val to_int : t -> int
(** [to_int true = 1], [to_int false = 0].
@since 2.7 *)

val of_int : int -> t
(** [of_int i] is the same as [i <> 0]
@since 2.7 *)
Expand Down
6 changes: 0 additions & 6 deletions src/core/CCChar.mli
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ include module type of struct
include Char
end

val compare : t -> t -> int
(** The comparison function for characters, with the same specification as
{!Stdlib.compare}. Along with the type [t], this function [compare]
allows the module [Char] to be passed as argument to the functors
{!Set.Make} and {!Map.Make}. *)

val of_int_exn : int -> t
(** Alias to {!Char.chr}.
Return the character with the given ASCII code.
Expand Down
8 changes: 8 additions & 0 deletions src/core/CCEither.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ type 'a equal = 'a -> 'a -> bool
type 'a ord = 'a -> 'a -> int
type 'a printer = Format.formatter -> 'a -> unit

[@@@ifge 4.12]

include Either

[@@@else_]

(** {2 Basics} *)

type ('a, 'b) t = ('a, 'b) Either.t =
Expand Down Expand Up @@ -62,6 +68,8 @@ let compare ~left ~right e1 e2 =
| Left l1, Left l2 -> left l1 l2
| Right r1, Right r2 -> right r1 r2

[@@@endif]

(** {2 IO} *)

let pp ~left ~right fmt = function
Expand Down
9 changes: 9 additions & 0 deletions src/core/CCEither.mli
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ type 'a equal = 'a -> 'a -> bool
type 'a ord = 'a -> 'a -> int
type 'a printer = Format.formatter -> 'a -> unit

[@@@ifge 4.12]

include module type of Either
(** @inline *)

[@@@else_]

(** {2 Basics} *)

type ('a, 'b) t = ('a, 'b) Either.t =
Expand Down Expand Up @@ -70,6 +77,8 @@ val compare :
('a, 'b) t ->
int

[@@@endif]

(** {2 IO} *)

val pp : left:'a printer -> right:'b printer -> ('a, 'b) t printer
Expand Down
60 changes: 1 addition & 59 deletions src/core/CCFloat.ml
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
(* This file is free software, part of containers. See file "license" for more details. *)

type t = float

type fpclass = Stdlib.fpclass =
| FP_normal
| FP_subnormal
| FP_zero
| FP_infinite
| FP_nan
include Float

module Infix = struct
let ( = ) : t -> t -> bool = Stdlib.( = )
Expand All @@ -27,47 +20,11 @@ include Infix

[@@@ocaml.warning "-32"]

let nan = Stdlib.nan
let infinity = Stdlib.infinity
let neg_infinity = Stdlib.neg_infinity
let max_value = infinity
let min_value = neg_infinity
let max_finite_value = Stdlib.max_float
let epsilon = Stdlib.epsilon_float
let pi = 0x1.921fb54442d18p+1
let is_nan x = Stdlib.(classify_float x = Stdlib.FP_nan)
let add = ( +. )
let sub = ( -. )
let mul = ( *. )
let div = ( /. )
let neg = ( ~-. )
let abs = Stdlib.abs_float
let scale = ( *. )

let min (x : t) y =
match Stdlib.classify_float x, Stdlib.classify_float y with
| FP_nan, _ -> y
| _, FP_nan -> x
| _ ->
if x < y then
x
else
y

let max (x : t) y =
match Stdlib.classify_float x, Stdlib.classify_float y with
| FP_nan, _ -> y
| _, FP_nan -> x
| _ ->
if x > y then
x
else
y

let equal (a : float) b = a = b
let hash : t -> int = Hashtbl.hash
let compare (a : float) b = Stdlib.compare a b

[@@@ocaml.warning "+32"]

type 'a printer = Format.formatter -> 'a -> unit
Expand All @@ -91,22 +48,7 @@ let sign_exn (a : float) =
else
compare a 0.

let round x =
let low = floor x in
let high = ceil x in
if x -. low > high -. x then
high
else
low

let to_int (a : float) = Stdlib.int_of_float a
let of_int (a : int) = Stdlib.float_of_int a
let to_string (a : float) = Stdlib.string_of_float a
let of_string_exn (a : string) = Stdlib.float_of_string a

let of_string_opt (a : string) =
try Some (Stdlib.float_of_string a) with Failure _ -> None

let random n st = Random.State.float st n
let random_small = random 100.0
let random_range i j st = i +. random (j -. i) st
Expand Down
Loading
Loading