• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MinaProtocol / mina / 751

30 Oct 2025 06:25PM UTC coverage: 36.978% (+3.5%) from 33.517%
751

push

buildkite

web-flow
Merge pull request #18037 from MinaProtocol/local-images

Replacing common images with ones in our repos

26959 of 72906 relevant lines covered (36.98%)

36217.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

48.0
/src/lib/mina_stdlib/list.ml
1
open Core_kernel
200✔
2
include List
3

4
module Length = struct
5
  type 'a t = ('a list, int) Sigs.predicate2
6

7
  let equal l len = Caml.List.compare_length_with l len = 0
×
8

9
  let unequal l len = Caml.List.compare_length_with l len <> 0
×
10

11
  let gte l len = Caml.List.compare_length_with l len >= 0
×
12

13
  let gt l len = Caml.List.compare_length_with l len > 0
×
14

15
  let lte l len = Caml.List.compare_length_with l len <= 0
×
16

17
  let lt l len = Caml.List.compare_length_with l len < 0
×
18

19
  module Compare = struct
20
    let ( = ) = equal
21

22
    let ( <> ) = unequal
23

24
    let ( >= ) = gte
25

26
    let ( > ) = gt
27

28
    let ( <= ) = lte
29

30
    let ( < ) = lt
31
  end
32
end
33

34
(** [process_separately] splits the list in two, and applies transformations
35
  * to both parts, then it merges the list back in the same order it was originally.
36
  * [process_left] and [process_right] are expected to return the same number
37
  * of elements processed in the same order.
38
  *)
39
let process_separately
40
    (type input left right left_output right_output output_item final_output)
41
    ~(partitioner : input -> (left, right) Either.t)
42
    ~(process_left : left list -> left_output)
43
    ~(process_right : right list -> right_output)
44
    ~(finalizer :
45
          left_output
46
       -> right_output
47
       -> f:(output_item list -> output_item list -> output_item list)
48
       -> final_output ) (input : input list) : final_output =
49
  let input_with_indices = List.mapi input ~f:(fun idx el -> (idx, el)) in
400✔
50
  let lefts, rights =
400✔
51
    List.partition_map input_with_indices ~f:(fun (idx, el) ->
52
        match partitioner el with
960✔
53
        | First x ->
×
54
            First (idx, x)
55
        | Second y ->
960✔
56
            Second (idx, y) )
57
  in
58
  let batch_process_snd ~f = Fn.compose (Tuple2.map_snd ~f) List.unzip in
400✔
59
  let lefts_idx, lefts_processed = batch_process_snd ~f:process_left lefts in
60
  let rights_idx, rights_processed =
400✔
61
    batch_process_snd ~f:process_right rights
62
  in
63

64
  finalizer lefts_processed rights_processed
400✔
65
    ~f:(fun left_materialized right_materialized ->
66
      let left_materialized_indexed =
400✔
67
        List.zip_exn lefts_idx left_materialized
68
      in
69
      let right_materialized_indexed =
400✔
70
        List.zip_exn rights_idx right_materialized
71
      in
72
      List.merge left_materialized_indexed right_materialized_indexed
400✔
73
        ~compare:(fun (left_idx, _) (right_idx, _) ->
74
          Int.compare left_idx right_idx )
×
75
      |> List.map ~f:snd )
76

77
let%test_module "process_separately" =
78
  ( module struct
79
    let%test "negate negative, div positive by 2" =
80
      let partitioner x = if x < 0 then First x else Second x in
×
81
      let process_left = List.map ~f:Int.neg in
82
      let process_right lst =
83
        let safe_div a b = match b with 0 -> None | x -> Some (a / b) in
×
84
        List.map ~f:(fun e -> safe_div e 2) lst |> Option.all
×
85
      in
86
      let finalizer left right_m ~f =
87
        match right_m with None -> [] | Some right -> f left right
×
88
      in
89
      process_separately ~partitioner ~process_left ~process_right ~finalizer
×
90
        [ -1; -3; -5; 4; -99; 8; 10 ]
91
      |> List.equal Int.equal [ 1; 3; 5; 2; 99; 4; 5 ]
92
  end )
400✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc