# All files / src/extensions Relude_Extensions_Foldable.bs.js

87.77% Statements 122/139
95.83% Branches 23/24
87.76% Functions 43/49
87.77% Lines 122/139

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299

    29x
    29x
    29x
    29x
    29x

    64x
    10x

    54x

    118x
    118x
    37x
    117x
    19x

    98x

    118x
    6x
    16x
    16x

    118x
    28x

    118x

    118x
    8x
    40x
    40x
    40x

    118x
    2x

    118x
    7x
    9x
    5x

    4x

    118x
    2x

    118x
    6x
    10x
    6x
    6x
    6x
    1x

    5x

    4x

    118x
    2x

    118x
    73x
    40163x
    40163x
    40161x

    2x

    118x
    71x
    40158x

    118x
    24x
    16x

    118x

    118x
    4x
    16x
    16x

    118x
    2x
    8x
    8x
    8x

    118x
    5x
    26x

    118x
    3x
    6x

    118x

    118x
    12x
    12x
    12x
    12x
    4x
    9x
    3x

    6x

    12x

    118x
    1x
    1x
    1x

    118x
    6x
    6x
    6x

    118x
    7x
    7x
    7x
    7x
    16x
    7x

    9x

    118x

    118x

    118x
    36x
    36x
    3x

    36x
    36x
    2x

    36x

    118x
    36x
    36x
    2x

    36x
    36x
    1x

    36x

    118x

    29x
    29x

     'use strict';

    var Curry = require("bs-platform/lib/js/curry.js");
    var Belt_Array = require("bs-platform/lib/js/belt_Array.js");
    var Caml_option = require("bs-platform/lib/js/caml_option.js");
    var Functions$BsAbstract = require("bs-abstract/lib/js/src/functions/Functions.bs.js");
    var Relude_Extensions_Ord = require("./Relude_Extensions_Ord.bs.js");

    function optionAlt(a, b) {
      if (a !== undefined) {
        return a;
      } else {
        return b;
      }
    }

    function FoldableExtensions(F) {
      var BsFoldableExtensions = Functions$BsAbstract.Foldable(F);
      var any = function (f, xs) {
        return Curry._3(F.fold_left, (function (v, x) {
                      if (v) {
                        return true;
                      } else {
                        return Curry._1(f, x);
                      }
                    }), false, xs);
      };
      var all = function (f, xs) {
        return Curry._3(F.fold_left, (function (v, x) {
                      Eif (v) {
                        return Curry._1(f, x);
                      } else {
                        return false;
                      }
                    }), true, xs);
      };
      var containsBy = function (f, x, xs) {
        return any(Curry._1(f, x), xs);
      };
      var contains = function (eqA, x, xs) {
        return any(Curry._1(eqA.eq, x), xs);
      };
      var indexOfBy = function (f, x, xs) {
        return Curry._3(F.fold_left, (function (param, y) {
                        var i = param[0];
                        var match = Curry._2(f, x, y);
                        return /* tuple */[
                                i + 1 | 0,
                                optionAlt(param[1], match ? i : undefined)
                              ];
                      }), /* tuple */[
                      0,
                      undefined
                    ], xs)[1];
      };
      var indexOf = function (eqA, x, xs) {
        return indexOfBy(eqA.eq, x, xs);
      };
      var minBy = function (f, xs) {
        return Curry._3(F.fold_left, (function (min, x) {
                      if (min !== undefined) {
                        return Caml_option.some(Relude_Extensions_Ord.minBy(f, x, Caml_option.valFromOption(min)));
                      } else {
                        return Caml_option.some(x);
                      }
                    }), undefined, xs);
      };
      var min = function (ordA, xs) {
        return minBy(ordA.compare, xs);
      };
      var maxBy = function (f, xs) {
        return Curry._3(F.fold_left, (function (min, x) {
                      if (min !== undefined) {
                        var y = Caml_option.valFromOption(min);
                        var match = Curry._2(f, x, y) === /* greater_than */159039494;
                        if (match) {
                          return Caml_option.some(x);
                        } else {
                          return Caml_option.some(y);
                        }
                      } else {
                        return Caml_option.some(x);
                      }
                    }), undefined, xs);
      };
      var max = function (ordA, xs) {
        return maxBy(ordA.compare, xs);
      };
      var countBy = function (f, xs) {
        return Curry._3(F.fold_left, (function (count, x) {
                      var match = Curry._1(f, x);
                      if (match) {
                        return count + 1 | 0;
                      } else {
                        return count;
                      }
                    }), 0, xs);
      };
      var length = function (xs) {
        return countBy((function (param) {
                      return true;
                    }), xs);
      };
      var forEach = function (f, xs) {
        return Curry._3(F.fold_left, (function (param, x) {
                      return Curry._1(f, x);
                    }), /* () */0, xs);
      };
      var forEachWithIndex = function (f, xs) {
        Curry._3(F.fold_left, (function (i, x) {
                Curry._2(f, x, i);
                return i + 1 | 0;
              }), 0, xs);
        return /* () */0;
      };
      var find = function (f) {
        return Curry._2(F.fold_left, (function (v, x) {
                      var match = Curry._1(f, x);
                      return optionAlt(v, match ? Caml_option.some(x) : undefined);
                    }), undefined);
      };
      var findWithIndex = function (f, xs) {
        return Curry._3(F.fold_left, (function (param, x) {
                        var i = param[0];
                        var match = Curry._2(f, x, i);
                        return /* tuple */[
                                i + 1 | 0,
                                optionAlt(param[1], match ? Caml_option.some(x) : undefined)
                              ];
                      }), /* tuple */[
                      0,
                      undefined
                    ], xs)[1];
      };
      var toList = function (fa) {
        return Curry._3(F.fold_right, (function (a, acc) {
                      return /* :: */[
                              a,
                              acc
                            ];
                    }), /* [] */0, fa);
      };
      var toArray = function (fa) {
        return Curry._3(F.fold_left, (function (acc, a) {
                      return Belt_Array.concat(acc, /* array */[a]);
                    }), /* array */[], fa);
      };
      var FoldableSemigroupExtensions = function (S) {
        var BsFoldableSemigroupExtensions = Curry._1(BsFoldableExtensions.Semigroup, S);
        var surroundMap = BsFoldableSemigroupExtensions.surround_map;
        var surround = BsFoldableSemigroupExtensions.surround;
        return {
                BsFoldableSemigroupExtensions: BsFoldableSemigroupExtensions,
                surroundMap: surroundMap,
                surround: surround
              };
      };
      var FoldableMonoidExtensions = function (M) {
        var BsFoldableMonoidExtensions = Curry._1(BsFoldableExtensions.Monoid, M);
        var foldMap = BsFoldableMonoidExtensions.FM.fold_map;
        var foldWithMonoid = BsFoldableMonoidExtensions.fold;
        var intercalate = function (sep, xs) {
          return Curry._3(F.fold_left, (function (param, x) {
                          if (param[0]) {
                            return /* tuple */[
                                    false,
                                    x
                                  ];
                          } else {
                            return /* tuple */[
                                    false,
                                    Curry._2(M.append, param[1], Curry._2(M.append, sep, x))
                                  ];
                          }
                        }), /* tuple */[
                        true,
                        M.empty
                      ], xs)[1];
        };
        return {
                BsFoldableMonoidExtensions: BsFoldableMonoidExtensions,
                foldMap: foldMap,
                foldWithMonoid: foldWithMonoid,
                intercalate: intercalate
              };
      };
      var foldMap = function (monoidA, f, xs) {
        var BsFoldableMonoidExtensions = Curry._1(BsFoldableExtensions.Monoid, monoidA);
        var foldMap$1 = BsFoldableMonoidExtensions.FM.fold_map;
        return Curry._2(foldMap$1, f, xs);
      };
      var foldWithMonoid = function (monoidA, xs) {
        var BsFoldableMonoidExtensions = Curry._1(BsFoldableExtensions.Monoid, monoidA);
        var foldWithMonoid$1 = BsFoldableMonoidExtensions.fold;
        return Curry._1(foldWithMonoid$1, xs);
      };
      var intercalate = function (monoidA, sep, xs) {
        Curry._1(BsFoldableExtensions.Monoid, monoidA);
        var sep$1 = sep;
        var xs$1 = xs;
        return Curry._3(F.fold_left, (function (param, x) {
                        if (param[0]) {
                          return /* tuple */[
                                  false,
                                  x
                                ];
                        } else {
                          return /* tuple */[
                                  false,
                                  Curry._2(monoidA.append, param[1], Curry._2(monoidA.append, sep$1, x))
                                ];
                        }
                      }), /* tuple */[
                      true,
                      monoidA.empty
                    ], xs$1)[1];
      };
      var FoldableApplicativeExtensions = function (A) {
        var BsFoldableApplicativeExtensions = Curry._1(BsFoldableExtensions.Applicative, A);
        var traverse_ = BsFoldableApplicativeExtensions.traverse$prime;
        var sequence_ = BsFoldableApplicativeExtensions.sequence$prime;
        return {
                BsFoldableApplicativeExtensions: BsFoldableApplicativeExtensions,
                traverse_: traverse_,
                sequence_: sequence_
              };
      };
      var FoldableMonadExtensions = function (M) {
        var BsFoldableMonadExtensions = Curry._1(BsFoldableExtensions.Monad, M);
        var foldWithMonad = BsFoldableMonadExtensions.fold_monad;
        return {
                BsFoldableMonadExtensions: BsFoldableMonadExtensions,
                foldWithMonad: foldWithMonad
              };
      };
      var FoldableEqExtensions = function (E) {
        var partial_arg = E.eq;
        var contains = function (param, param$1) {
          return any(Curry._1(partial_arg, param), param$1);
        };
        var partial_arg$1 = E.eq;
        var indexOf = function (param, param$1) {
          return indexOfBy(partial_arg$1, param, param$1);
        };
        return {
                contains: contains,
                indexOf: indexOf
              };
      };
      var FoldableOrdExtensions = function (O) {
        var partial_arg = O.compare;
        var min = function (param) {
          return minBy(partial_arg, param);
        };
        var partial_arg$1 = O.compare;
        var max = function (param) {
          return maxBy(partial_arg$1, param);
        };
        return {
                min: min,
                max: max
              };
      };
      return {
              BsFoldableExtensions: BsFoldableExtensions,
              any: any,
              all: all,
              containsBy: containsBy,
              contains: contains,
              indexOfBy: indexOfBy,
              indexOf: indexOf,
              minBy: minBy,
              min: min,
              maxBy: maxBy,
              max: max,
              countBy: countBy,
              length: length,
              forEach: forEach,
              forEachWithIndex: forEachWithIndex,
              find: find,
              findWithIndex: findWithIndex,
              toList: toList,
              toArray: toArray,
              FoldableSemigroupExtensions: FoldableSemigroupExtensions,
              FoldableMonoidExtensions: FoldableMonoidExtensions,
              foldMap: foldMap,
              foldWithMonoid: foldWithMonoid,
              intercalate: intercalate,
              FoldableApplicativeExtensions: FoldableApplicativeExtensions,
              FoldableMonadExtensions: FoldableMonadExtensions,
              FoldableEqExtensions: FoldableEqExtensions,
              FoldableOrdExtensions: FoldableOrdExtensions
            };
    }

    exports.optionAlt = optionAlt;
    exports.FoldableExtensions = FoldableExtensions;
    /* Functions-BsAbstract Not a pure module */