@elyukai/utils 0.2.5 → 0.2.8

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
@@ -2,6 +2,18 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [0.2.8](https://github.com/elyukai/ts-utils/compare/v0.2.7...v0.2.8) (2026-02-24)
6
+
7
+ ## [0.2.7](https://github.com/elyukai/ts-utils/compare/v0.2.6...v0.2.7) (2026-02-24)
8
+
9
+ ## [0.2.6](https://github.com/elyukai/ts-utils/compare/v0.2.5...v0.2.6) (2026-02-24)
10
+
11
+
12
+ ### Features
13
+
14
+ * add static traverse method to Reader ([693840d](https://github.com/elyukai/ts-utils/commit/693840dde90a0f4d650b0e075610e21a6b1a4318))
15
+ * safe non-empty array map method call ([5a97a69](https://github.com/elyukai/ts-utils/commit/5a97a69f25ac8431d3bc29405b312f750f0e30b9))
16
+
5
17
  ## [0.2.5](https://github.com/elyukai/ts-utils/compare/v0.2.4...v0.2.5) (2026-02-22)
6
18
 
7
19
 
package/dist/reader.d.ts CHANGED
@@ -50,6 +50,10 @@ export declare class Reader<in R, out T> {
50
50
  * Computes the result by providing the required environment.
51
51
  */
52
52
  run(env: R): T;
53
+ /**
54
+ * Apply a function to each value in the array, and return a Reader that produces an array of the results.
55
+ */
56
+ static traverse<T, R, U>(values: T[], fn: (value: T) => Reader<R, U>): Reader<R, U[]>;
53
57
  /**
54
58
  * Evaluate each reader in the array, and collect the results in a single reader instance.
55
59
  */
package/dist/reader.js CHANGED
@@ -2,6 +2,7 @@
2
2
  * A simple implementation of the Reader monad, which allows you to write functions that depend on some shared environment.
3
3
  * @module
4
4
  */
5
+ import { identity } from "./function.js";
5
6
  // A simpler wrapper for working with text that is generated based on different contexts, which encapsulates the context and reduces main code clutter. The context is only applied in the end.
6
7
  /**
7
8
  * The Reader monad represents a computation that depends on some shared environment. It allows you to write functions that can access this environment without having to pass it explicitly as an argument.
@@ -71,11 +72,17 @@ export class Reader {
71
72
  run(env) {
72
73
  return this.#fn(env);
73
74
  }
75
+ /**
76
+ * Apply a function to each value in the array, and return a Reader that produces an array of the results.
77
+ */
78
+ static traverse(values, fn) {
79
+ return new Reader((env) => values.map((value) => fn(value).run(env)));
80
+ }
74
81
  /**
75
82
  * Evaluate each reader in the array, and collect the results in a single reader instance.
76
83
  */
77
84
  static sequence(readers) {
78
- return new Reader((env) => readers.map((reader) => reader.run(env)));
85
+ return Reader.traverse(readers, identity);
79
86
  }
80
87
  /**
81
88
  * Transforms a function that returns a Reader into a Reader that produces a function.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyukai/utils",
3
- "version": "0.2.5",
3
+ "version": "0.2.8",
4
4
  "description": "A set of JavaScript helper functions.",
5
5
  "files": [
6
6
  "dist",