happy-rusty 1.8.0 → 1.9.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/CHANGELOG.md CHANGED
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.9.0] - 2026-01-04
9
+
10
+ ### Added
11
+ - **Try Extensions for Result**:
12
+ - `andTryAsync<U>` - Like `andThenAsync`, but auto-catches exceptions/Promise rejections and converts them to `Err`
13
+ - `orTryAsync<F>` - Like `orElseAsync`, but auto-catches exceptions in recovery logic
14
+
15
+ ### Changed
16
+ - **Performance**: `map()` and `mapErr()` now return `this` when the Result variant doesn't match, avoiding unnecessary object creation
17
+
18
+ ### Removed
19
+ - `promiseToAsyncResult()` - Use `tryAsyncResult()` instead (deprecated since v1.7.0)
20
+
8
21
  ## [1.8.0] - 2025-12-31
9
22
 
10
23
  ### Added
@@ -257,6 +270,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
257
270
  - Full TypeScript support
258
271
  - Comprehensive API matching Rust's Option and Result
259
272
 
273
+ [1.9.0]: https://github.com/JiangJie/happy-rusty/compare/v1.8.0...v1.9.0
260
274
  [1.8.0]: https://github.com/JiangJie/happy-rusty/compare/v1.7.1...v1.8.0
261
275
  [1.7.1]: https://github.com/JiangJie/happy-rusty/compare/v1.7.0...v1.7.1
262
276
  [1.7.0]: https://github.com/JiangJie/happy-rusty/compare/v1.6.2...v1.7.0
package/dist/main.cjs CHANGED
@@ -318,7 +318,7 @@ function Ok(value) {
318
318
  return Ok(fn(value));
319
319
  },
320
320
  mapErr(_fn) {
321
- return Ok(value);
321
+ return ok;
322
322
  },
323
323
  mapOr(_defaultValue, fn) {
324
324
  return fn(value);
@@ -365,6 +365,20 @@ function Ok(value) {
365
365
  },
366
366
  asErr() {
367
367
  throw new TypeError("Result::asErr() called on an `Ok` value");
368
+ },
369
+ andTryAsync(fn) {
370
+ try {
371
+ const result = fn(value);
372
+ return Promise.resolve(result).then(
373
+ Ok,
374
+ Err
375
+ );
376
+ } catch (e) {
377
+ return Promise.resolve(Err(e));
378
+ }
379
+ },
380
+ orTryAsync(_fn) {
381
+ return Promise.resolve(ok);
368
382
  }
369
383
  });
370
384
  return ok;
@@ -433,7 +447,7 @@ function Err(error) {
433
447
  return Some(err);
434
448
  },
435
449
  map(_fn) {
436
- return Err(error);
450
+ return err;
437
451
  },
438
452
  mapErr(fn) {
439
453
  return Err(fn(error));
@@ -482,6 +496,20 @@ function Err(error) {
482
496
  },
483
497
  asErr() {
484
498
  return err;
499
+ },
500
+ andTryAsync(_fn) {
501
+ return Promise.resolve(err);
502
+ },
503
+ orTryAsync(fn) {
504
+ try {
505
+ const result = fn(error);
506
+ return Promise.resolve(result).then(
507
+ Ok,
508
+ Err
509
+ );
510
+ } catch (e) {
511
+ return Promise.resolve(Err(e));
512
+ }
485
513
  }
486
514
  });
487
515
  return err;
@@ -549,9 +577,6 @@ async function tryAsyncResult(task, ...args) {
549
577
  return Err(err);
550
578
  }
551
579
  }
552
- async function promiseToAsyncResult(task) {
553
- return tryAsyncResult(task);
554
- }
555
580
 
556
581
  const ControlFlowKindSymbol = /* @__PURE__ */ Symbol("ControlFlow kind");
557
582
 
@@ -1500,7 +1525,6 @@ exports.Some = Some;
1500
1525
  exports.isControlFlow = isControlFlow;
1501
1526
  exports.isOption = isOption;
1502
1527
  exports.isResult = isResult;
1503
- exports.promiseToAsyncResult = promiseToAsyncResult;
1504
1528
  exports.tryAsyncOption = tryAsyncOption;
1505
1529
  exports.tryAsyncResult = tryAsyncResult;
1506
1530
  exports.tryOption = tryOption;