Skip to content

Commit

Permalink
Move list equality to Caqti_common_priv.
Browse files Browse the repository at this point in the history
  • Loading branch information
paurkedal committed Oct 17, 2020
1 parent 6eb186b commit 983705c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
6 changes: 6 additions & 0 deletions lib/caqti_common_priv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ module List = struct
let rec iter_r f = function
| [] -> Ok ()
| x :: xs -> (match f x with Ok () -> iter_r f xs | Error _ as r -> r)

let rec equal f xs ys =
(match xs, ys with
| [], [] -> true
| x :: xs', y :: ys' -> f x y && equal f xs' ys'
| [], _ :: _ | _ :: _, [] -> false)
end

let finally cleanup thunk =
Expand Down
1 change: 1 addition & 0 deletions lib/caqti_common_priv.mli
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module List : sig
val fold : ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b
val fold_r : ('a -> 'b -> ('b, 'e) result) -> 'a list -> 'b -> ('b, 'e) result
val iter_r : ('a -> (unit, 'e) result) -> 'a list -> (unit, 'e) result
val equal : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool
end

val finally : (unit -> unit) -> (unit -> 'a) -> 'a
Expand Down
10 changes: 3 additions & 7 deletions lib/caqti_query.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*)

open Caqti_common_priv

type t =
| L of string
| Q of string
Expand Down Expand Up @@ -45,13 +47,7 @@ let rec equal t1 t2 =
| L s1, L s2 -> String.equal s1 s2
| Q s1, Q s2 -> String.equal s1 s2
| P i1, P i2 -> Int.equal i1 i2
| S l1, S l2 ->
let rec list_equal a b =
match (a, b) with
| ([], []) -> true
| (a::x, b::y) -> equal a b && (list_equal x y)
| _ -> false in
list_equal l1 l2
| S ts1, S ts2 -> List.equal equal ts1 ts2
| L _, _ -> false
| Q _, _ -> false
| P _, _ -> false
Expand Down

0 comments on commit 983705c

Please sign in to comment.