@nlozgachev/pipelined 0.57.0 → 0.59.0

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/dist/core.d.ts CHANGED
@@ -1327,6 +1327,148 @@ declare namespace Optional {
1327
1327
  const andThenLens: <A, B>(inner: Lens<A, B>) => <S>(outer: Optional<S, A>) => Optional<S, B>;
1328
1328
  }
1329
1329
 
1330
+ /**
1331
+ * Pair<A, B> represents a pair of two values that are always both present.
1332
+ * It is a typed alias for `readonly [A, B]`.
1333
+ *
1334
+ * Use Pair when two values always travel together through a pipeline and you
1335
+ * want to transform either or both sides without destructuring.
1336
+ *
1337
+ * @example
1338
+ * ```ts
1339
+ * import { Pair } from "@nlozgachev/pipelined/core";
1340
+ * import { pipe } from "@nlozgachev/pipelined/composition";
1341
+ *
1342
+ * const entry = Pair.from.pair("alice", 42);
1343
+ *
1344
+ * pipe(
1345
+ * entry,
1346
+ * Pair.mapFirst((name) => name.toUpperCase()),
1347
+ * Pair.mapSecond((score) => score * 2),
1348
+ * Pair.fold((name, score) => `${name}: ${score}`),
1349
+ * ); // "ALICE: 84"
1350
+ * ```
1351
+ */
1352
+ type Pair<A, B> = readonly [A, B];
1353
+ declare namespace Pair {
1354
+ namespace from {
1355
+ /**
1356
+ * Creates a Pair from two values.
1357
+ *
1358
+ * @example
1359
+ * ```ts
1360
+ * Pair.from.pair("Paris", 2_161_000); // ["Paris", 2161000]
1361
+ * ```
1362
+ */
1363
+ const pair: <A, B>(first: A, second: B) => Pair<A, B>;
1364
+ /**
1365
+ * Creates a Pair from a two-element array.
1366
+ *
1367
+ * @example
1368
+ * ```ts
1369
+ * Pair.from.array(["Paris", 2_161_000] as const); // ["Paris", 2161000]
1370
+ * ```
1371
+ */
1372
+ const array: <A, B>(arr: readonly [A, B]) => Pair<A, B>;
1373
+ }
1374
+ /**
1375
+ * Returns the first value from the pair.
1376
+ *
1377
+ * @example
1378
+ * ```ts
1379
+ * Pair.first(Pair.from.pair("Paris", 2_161_000)); // "Paris"
1380
+ * ```
1381
+ */
1382
+ const first: <A, B>(p: Pair<A, B>) => A;
1383
+ /**
1384
+ * Returns the second value from the pair.
1385
+ *
1386
+ * @example
1387
+ * ```ts
1388
+ * Pair.second(Pair.from.pair("Paris", 2_161_000)); // 2161000
1389
+ * ```
1390
+ */
1391
+ const second: <A, B>(p: Pair<A, B>) => B;
1392
+ /**
1393
+ * Transforms the first value, leaving the second unchanged.
1394
+ *
1395
+ * @example
1396
+ * ```ts
1397
+ * pipe(Pair.from.pair("alice", 42), Pair.mapFirst((s) => s.toUpperCase())); // ["ALICE", 42]
1398
+ * ```
1399
+ */
1400
+ const mapFirst: <A, C>(f: (a: A) => C) => <B>(p: Pair<A, B>) => Pair<C, B>;
1401
+ /**
1402
+ * Transforms the second value, leaving the first unchanged.
1403
+ *
1404
+ * @example
1405
+ * ```ts
1406
+ * pipe(Pair.from.pair("alice", 42), Pair.mapSecond((n) => n * 2)); // ["alice", 84]
1407
+ * ```
1408
+ */
1409
+ const mapSecond: <B, D>(f: (b: B) => D) => <A>(p: Pair<A, B>) => Pair<A, D>;
1410
+ /**
1411
+ * Transforms both values independently in a single step.
1412
+ *
1413
+ * @example
1414
+ * ```ts
1415
+ * pipe(
1416
+ * Pair.from.pair("alice", 42),
1417
+ * Pair.mapBoth(
1418
+ * (name) => name.toUpperCase(),
1419
+ * (score) => score * 2,
1420
+ * ),
1421
+ * ); // ["ALICE", 84]
1422
+ * ```
1423
+ */
1424
+ const mapBoth: <A, C, B, D>(onFirst: (a: A) => C, onSecond: (b: B) => D) => (p: Pair<A, B>) => Pair<C, D>;
1425
+ /**
1426
+ * Applies a binary function to both values, collapsing the pair into a single value.
1427
+ * Useful as the final step when consuming a pair in a pipeline.
1428
+ *
1429
+ * @example
1430
+ * ```ts
1431
+ * pipe(Pair.from.pair("Alice", 100), Pair.fold((name, score) => `${name}: ${score}`));
1432
+ * // "Alice: 100"
1433
+ * ```
1434
+ */
1435
+ const fold: <A, B, C>(f: (a: A, b: B) => C) => (p: Pair<A, B>) => C;
1436
+ /**
1437
+ * Swaps the two values: `[A, B]` becomes `[B, A]`.
1438
+ *
1439
+ * @example
1440
+ * ```ts
1441
+ * Pair.swap(Pair.from.pair("key", 1)); // [1, "key"]
1442
+ * ```
1443
+ */
1444
+ const swap: <A, B>(p: Pair<A, B>) => Pair<B, A>;
1445
+ namespace to {
1446
+ /**
1447
+ * Converts the pair to a heterogeneous readonly array `readonly (A | B)[]`.
1448
+ *
1449
+ * @example
1450
+ * ```ts
1451
+ * Pair.to.Array(Pair.from.pair("hello", 42)); // ["hello", 42]
1452
+ * ```
1453
+ */
1454
+ const Array: <A, B>(p: Pair<A, B>) => readonly (A | B)[];
1455
+ }
1456
+ /**
1457
+ * Runs a side effect with both values without changing the pair.
1458
+ * Useful for logging or debugging in the middle of a pipeline.
1459
+ *
1460
+ * @example
1461
+ * ```ts
1462
+ * pipe(
1463
+ * Pair.from.pair("Paris", 2_161_000),
1464
+ * Pair.tap((city, pop) => console.log(`${city}: ${pop}`)),
1465
+ * Pair.mapSecond((n) => n / 1_000_000),
1466
+ * ); // logs "Paris: 2161000", returns ["Paris", 2.161]
1467
+ * ```
1468
+ */
1469
+ const tap: <A, B>(f: (a: A, b: B) => void) => (p: Pair<A, B>) => Pair<A, B>;
1470
+ }
1471
+
1330
1472
  /**
1331
1473
  * A boolean-valued function over a type `A`.
1332
1474
  *
@@ -2877,146 +3019,4 @@ declare namespace These {
2877
3019
  const swap: <A, B>(data: These<A, B>) => These<B, A>;
2878
3020
  }
2879
3021
 
2880
- /**
2881
- * Tuple<A, B> represents a pair of two values that are always both present.
2882
- * It is a typed alias for `readonly [A, B]`.
2883
- *
2884
- * Use Tuple when two values always travel together through a pipeline and you
2885
- * want to transform either or both sides without destructuring.
2886
- *
2887
- * @example
2888
- * ```ts
2889
- * import { Tuple } from "@nlozgachev/pipelined/core";
2890
- * import { pipe } from "@nlozgachev/pipelined/composition";
2891
- *
2892
- * const entry = Tuple.from.pair("alice", 42);
2893
- *
2894
- * pipe(
2895
- * entry,
2896
- * Tuple.mapFirst((name) => name.toUpperCase()),
2897
- * Tuple.mapSecond((score) => score * 2),
2898
- * Tuple.fold((name, score) => `${name}: ${score}`),
2899
- * ); // "ALICE: 84"
2900
- * ```
2901
- */
2902
- type Tuple<A, B> = readonly [A, B];
2903
- declare namespace Tuple {
2904
- namespace from {
2905
- /**
2906
- * Creates a pair from two values.
2907
- *
2908
- * @example
2909
- * ```ts
2910
- * Tuple.from.pair("Paris", 2_161_000); // ["Paris", 2161000]
2911
- * ```
2912
- */
2913
- const pair: <A, B>(first: A, second: B) => Tuple<A, B>;
2914
- /**
2915
- * Creates a Tuple from a two-element array.
2916
- *
2917
- * @example
2918
- * ```ts
2919
- * Tuple.from.array(["Paris", 2_161_000] as const); // ["Paris", 2161000]
2920
- * ```
2921
- */
2922
- const array: <A, B>(arr: readonly [A, B]) => Tuple<A, B>;
2923
- }
2924
- /**
2925
- * Returns the first value from the pair.
2926
- *
2927
- * @example
2928
- * ```ts
2929
- * Tuple.first(Tuple.from.pair("Paris", 2_161_000)); // "Paris"
2930
- * ```
2931
- */
2932
- const first: <A, B>(tuple: Tuple<A, B>) => A;
2933
- /**
2934
- * Returns the second value from the pair.
2935
- *
2936
- * @example
2937
- * ```ts
2938
- * Tuple.second(Tuple.from.pair("Paris", 2_161_000)); // 2161000
2939
- * ```
2940
- */
2941
- const second: <A, B>(tuple: Tuple<A, B>) => B;
2942
- /**
2943
- * Transforms the first value, leaving the second unchanged.
2944
- *
2945
- * @example
2946
- * ```ts
2947
- * pipe(Tuple.from.pair("alice", 42), Tuple.mapFirst((s) => s.toUpperCase())); // ["ALICE", 42]
2948
- * ```
2949
- */
2950
- const mapFirst: <A, C>(f: (a: A) => C) => <B>(tuple: Tuple<A, B>) => Tuple<C, B>;
2951
- /**
2952
- * Transforms the second value, leaving the first unchanged.
2953
- *
2954
- * @example
2955
- * ```ts
2956
- * pipe(Tuple.from.pair("alice", 42), Tuple.mapSecond((n) => n * 2)); // ["alice", 84]
2957
- * ```
2958
- */
2959
- const mapSecond: <B, D>(f: (b: B) => D) => <A>(tuple: Tuple<A, B>) => Tuple<A, D>;
2960
- /**
2961
- * Transforms both values independently in a single step.
2962
- *
2963
- * @example
2964
- * ```ts
2965
- * pipe(
2966
- * Tuple.from.pair("alice", 42),
2967
- * Tuple.mapBoth(
2968
- * (name) => name.toUpperCase(),
2969
- * (score) => score * 2,
2970
- * ),
2971
- * ); // ["ALICE", 84]
2972
- * ```
2973
- */
2974
- const mapBoth: <A, C, B, D>(onFirst: (a: A) => C, onSecond: (b: B) => D) => (tuple: Tuple<A, B>) => Tuple<C, D>;
2975
- /**
2976
- * Applies a binary function to both values, collapsing the pair into a single value.
2977
- * Useful as the final step when consuming a pair in a pipeline.
2978
- *
2979
- * @example
2980
- * ```ts
2981
- * pipe(Tuple.from.pair("Alice", 100), Tuple.fold((name, score) => `${name}: ${score}`));
2982
- * // "Alice: 100"
2983
- * ```
2984
- */
2985
- const fold: <A, B, C>(f: (a: A, b: B) => C) => (tuple: Tuple<A, B>) => C;
2986
- /**
2987
- * Swaps the two values: `[A, B]` becomes `[B, A]`.
2988
- *
2989
- * @example
2990
- * ```ts
2991
- * Tuple.swap(Tuple.from.pair("key", 1)); // [1, "key"]
2992
- * ```
2993
- */
2994
- const swap: <A, B>(tuple: Tuple<A, B>) => Tuple<B, A>;
2995
- namespace to {
2996
- /**
2997
- * Converts the pair to a heterogeneous readonly array `readonly (A | B)[]`.
2998
- *
2999
- * @example
3000
- * ```ts
3001
- * Tuple.to.Array(Tuple.from.pair("hello", 42)); // ["hello", 42]
3002
- * ```
3003
- */
3004
- const Array: <A, B>(tuple: Tuple<A, B>) => readonly (A | B)[];
3005
- }
3006
- /**
3007
- * Runs a side effect with both values without changing the pair.
3008
- * Useful for logging or debugging in the middle of a pipeline.
3009
- *
3010
- * @example
3011
- * ```ts
3012
- * pipe(
3013
- * Tuple.from.pair("Paris", 2_161_000),
3014
- * Tuple.tap((city, pop) => console.log(`${city}: ${pop}`)),
3015
- * Tuple.mapSecond((n) => n / 1_000_000),
3016
- * ); // logs "Paris: 2161000", returns ["Paris", 2.161]
3017
- * ```
3018
- */
3019
- const tap: <A, B>(f: (a: A, b: B) => void) => (tuple: Tuple<A, B>) => Tuple<A, B>;
3020
- }
3021
-
3022
- export { Combinable, Deferred, type Failure, Lazy, Lens, type Loading, Logged, Maybe, type NotAsked, Op, Optional, Predicate, Reader, Refinement, RemoteData, Resource, Result, State, Stream, type Success, Task, These, type TheseBoth, type TheseFirst, type TheseSecond, Tuple };
3022
+ export { Combinable, Deferred, type Failure, Lazy, Lens, type Loading, Logged, Maybe, type NotAsked, Op, Optional, Pair, Predicate, Reader, Refinement, RemoteData, Resource, Result, State, Stream, type Success, Task, These, type TheseBoth, type TheseFirst, type TheseSecond };
@@ -1,7 +1,3 @@
1
- import {
2
- Duration
3
- } from "./chunk-OIIOGDHK.js";
4
-
5
1
  // src/Core/Combinable.ts
6
2
  var Combinable;
7
3
  ((Combinable2) => {
@@ -232,6 +228,34 @@ var Maybe;
232
228
  Maybe3.transposeResult = (data) => is.none(data) ? Result.make.ok(make.none()) : Result.is.ok(data.value) ? Result.make.ok(make.some(data.value.value)) : Result.make.err(data.value.error);
233
229
  })(Maybe || (Maybe = {}));
234
230
 
231
+ // src/Types/Brand.ts
232
+ var Brand;
233
+ ((Brand2) => {
234
+ Brand2.wrap = () => (value) => value;
235
+ Brand2.unwrap = (branded) => branded;
236
+ })(Brand || (Brand = {}));
237
+
238
+ // src/Types/Duration.ts
239
+ var Duration;
240
+ ((Duration2) => {
241
+ const wrap = Brand.wrap();
242
+ Duration2.milliseconds = (ms) => wrap(ms);
243
+ Duration2.seconds = (s) => wrap(s * 1e3);
244
+ Duration2.minutes = (m) => wrap(m * 60 * 1e3);
245
+ Duration2.hours = (h) => wrap(h * 60 * 60 * 1e3);
246
+ Duration2.days = (d) => wrap(d * 24 * 60 * 60 * 1e3);
247
+ let to;
248
+ ((to2) => {
249
+ to2.milliseconds = (d) => Brand.unwrap(d);
250
+ to2.seconds = (d) => Brand.unwrap(d) / 1e3;
251
+ to2.minutes = (d) => Brand.unwrap(d) / (60 * 1e3);
252
+ to2.hours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
253
+ to2.days = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
254
+ })(to = Duration2.to || (Duration2.to = {}));
255
+ Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
256
+ Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
257
+ })(Duration || (Duration = {}));
258
+
235
259
  // src/internal/Op.util.ts
236
260
  var _abortedNil = { kind: "OpNil", reason: "aborted" };
237
261
  var _droppedNil = { kind: "OpNil", reason: "dropped" };
@@ -1402,6 +1426,34 @@ var Ordering;
1402
1426
  };
1403
1427
  })(Ordering || (Ordering = {}));
1404
1428
 
1429
+ // src/Core/Pair.ts
1430
+ var Pair;
1431
+ ((Pair2) => {
1432
+ let from;
1433
+ ((from2) => {
1434
+ from2.pair = (first2, second2) => [first2, second2];
1435
+ from2.array = (arr) => arr;
1436
+ })(from = Pair2.from || (Pair2.from = {}));
1437
+ Pair2.first = (p) => p[0];
1438
+ Pair2.second = (p) => p[1];
1439
+ Pair2.mapFirst = (f) => (p) => [f(p[0]), p[1]];
1440
+ Pair2.mapSecond = (f) => (p) => [p[0], f(p[1])];
1441
+ Pair2.mapBoth = (onFirst, onSecond) => (p) => [
1442
+ onFirst(p[0]),
1443
+ onSecond(p[1])
1444
+ ];
1445
+ Pair2.fold = (f) => (p) => f(p[0], p[1]);
1446
+ Pair2.swap = (p) => [p[1], p[0]];
1447
+ let to;
1448
+ ((to2) => {
1449
+ to2.Array = (p) => [...p];
1450
+ })(to = Pair2.to || (Pair2.to = {}));
1451
+ Pair2.tap = (f) => (p) => {
1452
+ f(p[0], p[1]);
1453
+ return p;
1454
+ };
1455
+ })(Pair || (Pair = {}));
1456
+
1405
1457
  // src/Core/Predicate.ts
1406
1458
  var Predicate;
1407
1459
  ((Predicate2) => {
@@ -2460,34 +2512,6 @@ var These;
2460
2512
  };
2461
2513
  })(These || (These = {}));
2462
2514
 
2463
- // src/Core/Tuple.ts
2464
- var Tuple;
2465
- ((Tuple2) => {
2466
- let from;
2467
- ((from2) => {
2468
- from2.pair = (first2, second2) => [first2, second2];
2469
- from2.array = (arr) => arr;
2470
- })(from = Tuple2.from || (Tuple2.from = {}));
2471
- Tuple2.first = (tuple) => tuple[0];
2472
- Tuple2.second = (tuple) => tuple[1];
2473
- Tuple2.mapFirst = (f) => (tuple) => [f(tuple[0]), tuple[1]];
2474
- Tuple2.mapSecond = (f) => (tuple) => [tuple[0], f(tuple[1])];
2475
- Tuple2.mapBoth = (onFirst, onSecond) => (tuple) => [
2476
- onFirst(tuple[0]),
2477
- onSecond(tuple[1])
2478
- ];
2479
- Tuple2.fold = (f) => (tuple) => f(tuple[0], tuple[1]);
2480
- Tuple2.swap = (tuple) => [tuple[1], tuple[0]];
2481
- let to;
2482
- ((to2) => {
2483
- to2.Array = (tuple) => [...tuple];
2484
- })(to = Tuple2.to || (Tuple2.to = {}));
2485
- Tuple2.tap = (f) => (tuple) => {
2486
- f(tuple[0], tuple[1]);
2487
- return tuple;
2488
- };
2489
- })(Tuple || (Tuple = {}));
2490
-
2491
2515
  // src/Core/Validation.ts
2492
2516
  var Validation;
2493
2517
  ((Validation2) => {
@@ -2593,7 +2617,6 @@ var Validation;
2593
2617
  return isNonEmptyArr(errors) ? make.failedAll(errors) : make.passed(record);
2594
2618
  };
2595
2619
  })(Validation || (Validation = {}));
2596
-
2597
2620
  export {
2598
2621
  Combinable,
2599
2622
  Deferred,
@@ -2605,6 +2628,7 @@ export {
2605
2628
  Op,
2606
2629
  Optional,
2607
2630
  Ordering,
2631
+ Pair,
2608
2632
  Predicate,
2609
2633
  Reader,
2610
2634
  Refinement,
@@ -2613,9 +2637,7 @@ export {
2613
2637
  Result,
2614
2638
  State,
2615
2639
  Stream,
2616
- isNonEmptyArr,
2617
2640
  Task,
2618
2641
  These,
2619
- Tuple,
2620
2642
  Validation
2621
2643
  };