@zelgadis87/utils-core 5.2.4 → 5.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esbuild/index.mjs CHANGED
@@ -488,6 +488,11 @@ var Optional = class _Optional {
488
488
  throw errorProducer();
489
489
  return this;
490
490
  }
491
+ throwIfPresent(errorProducer) {
492
+ if (this.isEmpty())
493
+ return this;
494
+ throw errorProducer(this.get());
495
+ }
491
496
  mapTo(mapper) {
492
497
  return this.flatMapTo((t) => _Optional.ofNullable(mapper(t)));
493
498
  }
@@ -832,19 +837,6 @@ function listToDict(arr, mapFn) {
832
837
  return { ...dict, [key]: value };
833
838
  }, {});
834
839
  }
835
- function countArrayBy(arr, mapFn) {
836
- return arr.reduce((dict, cur) => {
837
- const value = mapFn(cur);
838
- const count = (dict[value] ?? 0) + 1;
839
- return { ...dict, [value]: count };
840
- }, {});
841
- }
842
- function sumArrayBy(arr, mapFn) {
843
- return arr.reduce((sum2, cur) => {
844
- const value = mapFn(cur);
845
- return sum2 + value;
846
- }, 0);
847
- }
848
840
  function shallowArrayEquals(a, b) {
849
841
  if (a === b) return true;
850
842
  if (a.length !== b.length) return false;
@@ -870,6 +862,11 @@ function unzip(arr) {
870
862
  return [[...ts, t], [...rs, r]];
871
863
  }, [[], []]);
872
864
  }
865
+ function arrayGet(arr, index) {
866
+ if (index < 0 || index >= arr.length)
867
+ return Optional_default.empty();
868
+ return Optional_default.of(arr[index]);
869
+ }
873
870
 
874
871
  // src/utils/booleans.ts
875
872
  function isTrue(x) {
@@ -1114,6 +1111,16 @@ function tryToParseNumber(numberStr) {
1114
1111
  });
1115
1112
  }
1116
1113
 
1114
+ // src/utils/operations.ts
1115
+ var Operation = {
1116
+ ok: (data) => {
1117
+ return { success: true, data };
1118
+ },
1119
+ ko: (error) => {
1120
+ return { success: false, error };
1121
+ }
1122
+ };
1123
+
1117
1124
  // src/utils/promises.ts
1118
1125
  function asPromise(promisable) {
1119
1126
  return Promise.resolve(promisable);
@@ -2810,6 +2817,7 @@ export {
2810
2817
  Logger,
2811
2818
  NEVER,
2812
2819
  NonExhaustiveSwitchError,
2820
+ Operation,
2813
2821
  Optional,
2814
2822
  PredicateBuilder,
2815
2823
  RandomTimeDuration,
@@ -2826,6 +2834,7 @@ export {
2826
2834
  alwaysFalse,
2827
2835
  alwaysTrue,
2828
2836
  and,
2837
+ arrayGet,
2829
2838
  asError,
2830
2839
  asPromise,
2831
2840
  average,
@@ -2840,7 +2849,6 @@ export {
2840
2849
  constantTrue,
2841
2850
  constantUndefined,
2842
2851
  constantZero,
2843
- countArrayBy,
2844
2852
  cssDeclarationRulesDictionaryToCss,
2845
2853
  decrement,
2846
2854
  decrementBy,
@@ -2957,7 +2965,6 @@ export {
2957
2965
  stringToNumber,
2958
2966
  stringifyJson,
2959
2967
  sum,
2960
- sumArrayBy,
2961
2968
  sumBy,
2962
2969
  tail,
2963
2970
  throttle,