# All files / src/array Relude_Array_Base.bs.js

89.42% Statements 186/208
82.76% Branches 48/58
87.5% Functions 56/64
89.42% Lines 186/208

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
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458

    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x

    2x

    5x
    3x

    21x

    23x

    2x
    8x

    2x

    2x

    2x

    14x

    3x
    1x

    3x

    19x
    19x
    2x
    17x
    4x

    13x
    13x
    13x
    13x

    16x
    16x
    15x

    1x

    6x
    6x
    2x

    4x

    3x
    3x
    2x

    1x

    3x
    3x
    1x

    2x

    9x
    9x

    9x

    9x
    9x

    9x

    5x
    2x

    3x

    10x
    10x
    8x
    8x
    6x
    6x

    2x

    2x

    5x
    5x

    5x

    5x
    5x

    5x

    5x
    1x

    4x

    4x
    10x
    10x
    10x
    6x
    6x

    4x

    1x

    1x

    1x
    1x
    4x

    1x
    1x
    4x

    3x
    13x
    5x

    1x
    3x

    1x

    1x

    1x

    3x
    5x

    2x
    2x
    1x
    1x

    1x

    3x
    3x

    1x

    6x

    1x

    2x
    20x

    1x

    1x
    12x
    12x
    6x

    6x

    1x
    5x
    1x

    4x

    1x
    5x
    5x

    1x
    5x
    5x

    23x

    23x

    23x

    23x

    23x

    23x

    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x
    23x

     'use strict';

    var Curry = require("bs-platform/lib/js/curry.js");
    var Belt_Array = require("bs-platform/lib/js/belt_Array.js");
    var Relude_Int = require("../Relude_Int.bs.js");
    var Caml_option = require("bs-platform/lib/js/caml_option.js");
    var Relude_Option = require("../Relude_Option.bs.js");
    var Belt_SortArray = require("bs-platform/lib/js/belt_SortArray.js");
    var Relude_Ordering = require("../Relude_Ordering.bs.js");
    var Relude_Array_Instances = require("./Relude_Array_Instances.bs.js");

    function cons(x, xs) {
      return Relude_Array_Instances.concat(/* array */[x], xs);
    }

    function uncons(xs) {
      if (xs.length !== 0) {
        return /* tuple */[
                Belt_Array.getExn(xs, 0),
                Belt_Array.sliceToEnd(xs, 1)
              ];
      }

    }

    function append(x, xs) {
      return Relude_Array_Instances.concat(xs, /* array */[x]);
    }

    var repeat = Belt_Array.make;

    function mapWithIndex(f, xs) {
      return Belt_Array.mapWithIndex(xs, (function (i, x) {
                    return Curry._2(f, x, i);
                  }));
    }

    function shuffleInPlace(xs) {
      Belt_Array.shuffleInPlace(xs);
      return xs;
    }

    function length(prim) {
      return prim.length;
    }

    function isEmpty(arr) {
      return arr.length === 0;
    }

    function isNotEmpty(arr) {
      return arr.length !== 0;
    }

    function at(i, xs) {
      return Belt_Array.get(xs, i);
    }

    function setAt(i, x, xs) {
      if (Belt_Array.set(xs, i, x)) {
        return xs;
      }

    }

    function head(arr) {
      return Belt_Array.get(arr, 0);
    }

    function tail(xs) {
      var l = xs.length;
      if (l === 0) {
        return ;
      } else if (l === 1) {
        return /* array */[];
      } else {
        var ys = Belt_Array.sliceToEnd(xs, 1);
        var match = ys.length !== 0;
        Eif (match) {
          return ys;
        } else {
          return ;
        }
      }
    }

    function tailOrEmpty(xs) {
      var match = tail(xs);
      if (match !== undefined) {
        return match;
      } else {
        return /* array */[];
      }
    }

    function init(xs) {
      var l = xs.length;
      if (l === 0) {
        return ;
      } else {
        return Belt_Array.slice(xs, 0, l - 1 | 0);
      }
    }

    function initOrEmpty(xs) {
      var match = init(xs);
      if (match !== undefined) {
        return match;
      } else {
        return /* array */[];
      }
    }

    function last(xs) {
      var l = xs.length;
      if (l === 0) {
        return ;
      } else {
        return Belt_Array.get(xs, l - 1 | 0);
      }
    }

    function take(i, xs) {
      var l = xs.length;
      var match = i < 0;
      var len;
      Iif (match) {
        len = 0;
      } else {
        var match$1 = l < i;
        len = match$1 ? l : i;
      }
      return Belt_Array.slice(xs, 0, len);
    }

    function takeExactly(i, xs) {
      if (i < 0 || i > xs.length) {
        return ;
      } else {
        return Belt_Array.slice(xs, 0, i);
      }
    }

    function takeWhile(f, xs) {
      var match = Belt_Array.get(xs, 0);
      if (match !== undefined) {
        var x = Caml_option.valFromOption(match);
        if (Curry._1(f, x)) {
          var xs$1 = takeWhile(f, tailOrEmpty(xs));
          return Relude_Array_Instances.concat(/* array */[x], xs$1);
        } else {
          return /* array */[];
        }
      } else {
        return /* array */[];
      }
    }

    function drop(i, xs) {
      var l = xs.length;
      var match = i < 0;
      var start;
      Iif (match) {
        start = 0;
      } else {
        var match$1 = l < i;
        start = match$1 ? l : i;
      }
      return Belt_Array.sliceToEnd(xs, start);
    }

    function dropExactly(i, xs) {
      if (i < 0 || i > xs.length) {
        return ;
      } else {
        return Belt_Array.sliceToEnd(xs, i);
      }
    }

    function dropWhile(f, _xs) {
      while(true) {
        var xs = _xs;
        var match = Belt_Array.get(xs, 0);
        if (match !== undefined && Curry._1(f, Caml_option.valFromOption(match))) {
          _xs = tailOrEmpty(xs);
          continue ;
        } else {
          return xs;
        }
      };
    }

    function filter(f, xs) {
      return Belt_Array.keep(xs, f);
    }

    function filterWithIndex(f, xs) {
      return Belt_Array.keepWithIndex(xs, f);
    }

    function filterNot(f) {
      return (function (param) {
          return Belt_Array.keep(param, (function (a) {
                        return !Curry._1(f, a);
                      }));
        });
    }

    function filterNotWithIndex(f) {
      return (function (param) {
          return Belt_Array.keepWithIndex(param, (function (a, i) {
                        return !Curry._2(f, a, i);
                      }));
        });
    }

    function mapOption(f, xs) {
      return Relude_Array_Instances.foldLeft((function (acc, curr) {
                      return Relude_Option.fold(acc, (function (v) {
                                    return Relude_Array_Instances.concat(acc, /* array */[v]);
                                  }), Curry._1(f, curr));
                    }), /* array */[])(xs);
    }

    function catOption(xs) {
      return mapOption((function (v) {
                    return v;
                  }), xs);
    }

    function partition(f, xs) {
      return Belt_Array.partition(xs, f);
    }

    function splitAt(i, xs) {
      Iif (i < 0 || i > xs.length) {
        return ;
      } else {
        return /* tuple */[
                Belt_Array.slice(xs, 0, i),
                Belt_Array.sliceToEnd(xs, i)
              ];
      }
    }

    function prependToAll(delim, xs) {
      return Curry._2(Relude_Array_Instances.flatMap, (function (v) {
                    return /* array */[
                            delim,
                            v
                          ];
                  }), xs);
    }

    function intersperse(delim, xs) {
      var match = Belt_Array.get(xs, 0);
      if (match !== undefined) {
        var xs$1 = prependToAll(delim, tailOrEmpty(xs));
        return Relude_Array_Instances.concat(/* array */[Caml_option.valFromOption(match)], xs$1);
      } else {
        return /* array */[];
      }
    }

    function replicate(i, xs) {
      return Relude_Array_Instances.foldLeft((function (acc, _i) {
                      return Relude_Array_Instances.concat(acc, xs);
                    }), /* array */[])(Relude_Int.rangeAsArray(0, i));
    }

    function zipWith(f, xs, ys) {
      return Belt_Array.zipBy(xs, ys, f);
    }

    function zipWithIndex(xs) {
      return Belt_Array.zip(xs, Relude_Int.rangeAsArray(0, xs.length));
    }

    function sortWithInt(f, xs) {
      return Belt_SortArray.stableSortBy(xs, f);
    }

    function sortBy(f, xs) {
      return Belt_SortArray.stableSortBy(xs, (function (a, b) {
                    return Relude_Ordering.toInt(Curry._2(f, a, b));
                  }));
    }

    function sort(ordA, xs) {
      return sortBy(ordA.compare, xs);
    }

    function distinctBy(eq, xs) {
      return Relude_Array_Instances.foldLeft((function (acc, curr) {
                      var match = Curry._3(Relude_Array_Instances.containsBy, eq, curr, acc);
                      if (match) {
                        return acc;
                      } else {
                        return Relude_Array_Instances.concat(acc, /* array */[curr]);
                      }
                    }), /* array */[])(xs);
    }

    function removeFirstBy(innerEq, v, xs) {
      return Relude_Array_Instances.foldLeft((function (param, x) {
                        var ys = param[1];
                        if (param[0]) {
                          return /* tuple */[
                                  true,
                                  Relude_Array_Instances.concat(ys, /* array */[x])
                                ];
                        } else {
                          var match = Curry._2(innerEq, v, x);
                          if (match) {
                            return /* tuple */[
                                    true,
                                    ys
                                  ];
                          } else {
                            return /* tuple */[
                                    false,
                                    Relude_Array_Instances.concat(ys, /* array */[x])
                                  ];
                          }
                        }
                      }), /* tuple */[
                      false,
                      /* array */[]
                    ])(xs)[1];
    }

    function removeEachBy(innerEq, x, xs) {
      return Relude_Array_Instances.foldLeft((function (ys, y) {
                      var match = Curry._2(innerEq, x, y);
                      if (match) {
                        return ys;
                      } else {
                        return Relude_Array_Instances.concat(ys, /* array */[y]);
                      }
                    }), /* array */[])(xs);
    }

    function distinct(eqA, xs) {
      return distinctBy(eqA.eq, xs);
    }

    function removeFirst(eqA, x, xs) {
      return removeFirstBy(eqA.eq, x, xs);
    }

    function removeEach(eqA, x, xs) {
      return removeEachBy(eqA.eq, x, xs);
    }

    function replaceAt(targetIndex, newX, xs) {
      return mapWithIndex((function (x, currentIndex) {
                    if (currentIndex === targetIndex) {
                      return newX;
                    } else {
                      return x;
                    }
                  }), xs);
    }

    function scanLeft(f, init, xs) {
      return Relude_Array_Instances.foldLeft((function (param, curr) {
                        var nextAcc = Curry._2(f, param[0], curr);
                        return /* tuple */[
                                nextAcc,
                                Relude_Array_Instances.concat(param[1], /* array */[nextAcc])
                              ];
                      }), /* tuple */[
                      init,
                      /* array */[]
                    ])(xs)[1];
    }

    function scanRight(f, init, xs) {
      return Relude_Array_Instances.foldRight((function (curr, param) {
                        var nextAcc = Curry._2(f, curr, param[0]);
                        return /* tuple */[
                                nextAcc,
                                Relude_Array_Instances.concat(/* array */[nextAcc], param[1])
                              ];
                      }), /* tuple */[
                      init,
                      /* array */[]
                    ])(xs)[1];
    }

    var prepend = cons;

    var makeWithIndex = Belt_Array.makeBy;

    var reverse = Belt_Array.reverse;

    var shuffle = Belt_Array.shuffle;

    var zip = Belt_Array.zip;

    var unzip = Belt_Array.unzip;

    exports.cons = cons;
    exports.prepend = prepend;
    exports.uncons = uncons;
    exports.append = append;
    exports.repeat = repeat;
    exports.makeWithIndex = makeWithIndex;
    exports.mapWithIndex = mapWithIndex;
    exports.reverse = reverse;
    exports.shuffleInPlace = shuffleInPlace;
    exports.shuffle = shuffle;
    exports.length = length;
    exports.isEmpty = isEmpty;
    exports.isNotEmpty = isNotEmpty;
    exports.at = at;
    exports.setAt = setAt;
    exports.head = head;
    exports.tail = tail;
    exports.tailOrEmpty = tailOrEmpty;
    exports.init = init;
    exports.initOrEmpty = initOrEmpty;
    exports.last = last;
    exports.take = take;
    exports.takeExactly = takeExactly;
    exports.takeWhile = takeWhile;
    exports.drop = drop;
    exports.dropExactly = dropExactly;
    exports.dropWhile = dropWhile;
    exports.filter = filter;
    exports.filterWithIndex = filterWithIndex;
    exports.filterNot = filterNot;
    exports.filterNotWithIndex = filterNotWithIndex;
    exports.mapOption = mapOption;
    exports.catOption = catOption;
    exports.partition = partition;
    exports.splitAt = splitAt;
    exports.prependToAll = prependToAll;
    exports.intersperse = intersperse;
    exports.replicate = replicate;
    exports.zip = zip;
    exports.zipWith = zipWith;
    exports.zipWithIndex = zipWithIndex;
    exports.unzip = unzip;
    exports.sortWithInt = sortWithInt;
    exports.sortBy = sortBy;
    exports.sort = sort;
    exports.distinctBy = distinctBy;
    exports.removeFirstBy = removeFirstBy;
    exports.removeEachBy = removeEachBy;
    exports.distinct = distinct;
    exports.removeFirst = removeFirst;
    exports.removeEach = removeEach;
    exports.replaceAt = replaceAt;
    exports.scanLeft = scanLeft;
    exports.scanRight = scanRight;
    /* Relude_Int Not a pure module */