@siteimprove/alfa-lazy 0.110.0 → 0.112.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
@@ -1,5 +1,13 @@
1
1
  # @siteimprove/alfa-lazy
2
2
 
3
+ ## 0.112.0
4
+
5
+ ### Patch Changes
6
+
7
+ - **Fixed:** `Lazy` whose underlying `Thunk` is stateful now correctly freeze their value upon evaluation, even across copies (e.g. mapped version of the `Lazy`). ([#2005](https://github.com/Siteimprove/alfa/pull/2005))
8
+
9
+ ## 0.111.0
10
+
3
11
  ## 0.110.0
4
12
 
5
13
  ## 0.109.0
package/dist/lazy.d.ts CHANGED
@@ -4,12 +4,17 @@ import type { Functor } from "@siteimprove/alfa-functor";
4
4
  import { Serializable } from "@siteimprove/alfa-json";
5
5
  import type { Mapper } from "@siteimprove/alfa-mapper";
6
6
  import type { Monad } from "@siteimprove/alfa-monad";
7
- import type { Thunk } from "@siteimprove/alfa-thunk";
7
+ import { Thunk } from "@siteimprove/alfa-thunk";
8
8
  import { Trampoline } from "@siteimprove/alfa-trampoline";
9
9
  /**
10
10
  * @public
11
11
  */
12
12
  export declare class Lazy<T> implements Functor<T>, Applicative<T>, Monad<T>, Iterable<T>, Equatable, Serializable<Lazy.JSON<T>> {
13
+ /**
14
+ * Create a new lazy value from a thunk.
15
+ * The Lazy will contain a frozen copy of the Thunk, ensuring it always produces
16
+ * the same value and thus can indeed be lazily evaluated.
17
+ */
13
18
  static of<T>(thunk: Thunk<T>): Lazy<T>;
14
19
  static force<T>(value: T): Lazy<T>;
15
20
  private _value;
package/dist/lazy.js CHANGED
@@ -1,12 +1,18 @@
1
1
  import { Equatable } from "@siteimprove/alfa-equatable";
2
2
  import { Serializable } from "@siteimprove/alfa-json";
3
+ import { Thunk } from "@siteimprove/alfa-thunk";
3
4
  import { Trampoline } from "@siteimprove/alfa-trampoline";
4
5
  /**
5
6
  * @public
6
7
  */
7
8
  export class Lazy {
9
+ /**
10
+ * Create a new lazy value from a thunk.
11
+ * The Lazy will contain a frozen copy of the Thunk, ensuring it always produces
12
+ * the same value and thus can indeed be lazily evaluated.
13
+ */
8
14
  static of(thunk) {
9
- return new Lazy(Trampoline.delay(thunk));
15
+ return new Lazy(Trampoline.delay(Thunk.freeze(thunk)));
10
16
  }
11
17
  static force(value) {
12
18
  return new Lazy(Trampoline.done(value));
@@ -16,10 +22,11 @@ export class Lazy {
16
22
  this._value = value;
17
23
  }
18
24
  force() {
25
+ const value = this._value.run();
19
26
  if (this._value.isSuspended()) {
20
- this._value = Trampoline.done(this._value.run());
27
+ this._value = Trampoline.done(value);
21
28
  }
22
- return this._value.run();
29
+ return value;
23
30
  }
24
31
  map(mapper) {
25
32
  return new Lazy(this._value.flatMap((value) => {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "$schema": "http://json.schemastore.org/package",
3
3
  "name": "@siteimprove/alfa-lazy",
4
4
  "homepage": "https://alfa.siteimprove.com",
5
- "version": "0.110.0",
5
+ "version": "0.112.0",
6
6
  "license": "MIT",
7
7
  "description": "An implementation of lazy values, which are values whose initialization can be delayed until needed",
8
8
  "repository": {
@@ -22,17 +22,17 @@
22
22
  "dist/**/*.d.ts"
23
23
  ],
24
24
  "dependencies": {
25
- "@siteimprove/alfa-applicative": "^0.110.0",
26
- "@siteimprove/alfa-equatable": "^0.110.0",
27
- "@siteimprove/alfa-functor": "^0.110.0",
28
- "@siteimprove/alfa-json": "^0.110.0",
29
- "@siteimprove/alfa-mapper": "^0.110.0",
30
- "@siteimprove/alfa-monad": "^0.110.0",
31
- "@siteimprove/alfa-thunk": "^0.110.0",
32
- "@siteimprove/alfa-trampoline": "^0.110.0"
25
+ "@siteimprove/alfa-applicative": "^0.112.0",
26
+ "@siteimprove/alfa-equatable": "^0.112.0",
27
+ "@siteimprove/alfa-functor": "^0.112.0",
28
+ "@siteimprove/alfa-json": "^0.112.0",
29
+ "@siteimprove/alfa-mapper": "^0.112.0",
30
+ "@siteimprove/alfa-monad": "^0.112.0",
31
+ "@siteimprove/alfa-thunk": "^0.112.0",
32
+ "@siteimprove/alfa-trampoline": "^0.112.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@siteimprove/alfa-test": "^0.110.0"
35
+ "@siteimprove/alfa-test": "^0.112.0"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public",