effect 3.1.0 → 3.1.2

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.
Files changed (278) hide show
  1. package/dist/cjs/Array.js +10 -13
  2. package/dist/cjs/Array.js.map +1 -1
  3. package/dist/cjs/BigDecimal.js +14 -17
  4. package/dist/cjs/BigDecimal.js.map +1 -1
  5. package/dist/cjs/BigInt.js +41 -46
  6. package/dist/cjs/BigInt.js.map +1 -1
  7. package/dist/cjs/Boolean.js +13 -13
  8. package/dist/cjs/Brand.js +2 -2
  9. package/dist/cjs/Chunk.js +3 -3
  10. package/dist/cjs/Context.js +15 -20
  11. package/dist/cjs/Context.js.map +1 -1
  12. package/dist/cjs/Cron.js +3 -6
  13. package/dist/cjs/Cron.js.map +1 -1
  14. package/dist/cjs/Data.js +8 -13
  15. package/dist/cjs/Data.js.map +1 -1
  16. package/dist/cjs/Duration.js +1 -1
  17. package/dist/cjs/Effect.js +77 -9
  18. package/dist/cjs/Effect.js.map +1 -1
  19. package/dist/cjs/Either.js +117 -59
  20. package/dist/cjs/Either.js.map +1 -1
  21. package/dist/cjs/Equal.js +26 -4
  22. package/dist/cjs/Equal.js.map +1 -1
  23. package/dist/cjs/FiberHandle.js.map +1 -1
  24. package/dist/cjs/FiberMap.js.map +1 -1
  25. package/dist/cjs/FiberSet.js.map +1 -1
  26. package/dist/cjs/Function.js +2 -2
  27. package/dist/cjs/Function.js.map +1 -1
  28. package/dist/cjs/Hash.js +29 -12
  29. package/dist/cjs/Hash.js.map +1 -1
  30. package/dist/cjs/Iterable.js +10 -13
  31. package/dist/cjs/Iterable.js.map +1 -1
  32. package/dist/cjs/List.js +2 -2
  33. package/dist/cjs/Metric.js +5 -7
  34. package/dist/cjs/Metric.js.map +1 -1
  35. package/dist/cjs/Number.js +20 -21
  36. package/dist/cjs/Number.js.map +1 -1
  37. package/dist/cjs/Option.js +223 -164
  38. package/dist/cjs/Option.js.map +1 -1
  39. package/dist/cjs/Order.js +1 -2
  40. package/dist/cjs/Order.js.map +1 -1
  41. package/dist/cjs/Ordering.js +2 -2
  42. package/dist/cjs/Predicate.js +9 -12
  43. package/dist/cjs/Predicate.js.map +1 -1
  44. package/dist/cjs/Readable.js.map +1 -1
  45. package/dist/cjs/Record.js +35 -47
  46. package/dist/cjs/Record.js.map +1 -1
  47. package/dist/cjs/RegExp.js +1 -1
  48. package/dist/cjs/Request.js +2 -2
  49. package/dist/cjs/Request.js.map +1 -1
  50. package/dist/cjs/Stream.js +82 -4
  51. package/dist/cjs/Stream.js.map +1 -1
  52. package/dist/cjs/String.js +81 -111
  53. package/dist/cjs/String.js.map +1 -1
  54. package/dist/cjs/Struct.js +13 -19
  55. package/dist/cjs/Struct.js.map +1 -1
  56. package/dist/cjs/Subscribable.js.map +1 -1
  57. package/dist/cjs/Symbol.js +3 -3
  58. package/dist/cjs/TestAnnotation.js.map +1 -1
  59. package/dist/cjs/TestAnnotationMap.js.map +1 -1
  60. package/dist/cjs/TestAnnotations.js.map +1 -1
  61. package/dist/cjs/TestClock.js.map +1 -1
  62. package/dist/cjs/TestLive.js.map +1 -1
  63. package/dist/cjs/TestSized.js.map +1 -1
  64. package/dist/cjs/Trie.js +28 -44
  65. package/dist/cjs/Trie.js.map +1 -1
  66. package/dist/cjs/Utils.js +35 -1
  67. package/dist/cjs/Utils.js.map +1 -1
  68. package/dist/cjs/internal/core-effect.js +4 -11
  69. package/dist/cjs/internal/core-effect.js.map +1 -1
  70. package/dist/cjs/internal/core.js +16 -4
  71. package/dist/cjs/internal/core.js.map +1 -1
  72. package/dist/cjs/internal/doNotation.js +23 -0
  73. package/dist/cjs/internal/doNotation.js.map +1 -0
  74. package/dist/cjs/internal/groupBy.js.map +1 -1
  75. package/dist/cjs/internal/stream.js +3 -7
  76. package/dist/cjs/internal/stream.js.map +1 -1
  77. package/dist/cjs/internal/version.js +1 -1
  78. package/dist/dts/Array.d.ts +10 -13
  79. package/dist/dts/Array.d.ts.map +1 -1
  80. package/dist/dts/BigDecimal.d.ts +14 -17
  81. package/dist/dts/BigDecimal.d.ts.map +1 -1
  82. package/dist/dts/BigInt.d.ts +41 -46
  83. package/dist/dts/BigInt.d.ts.map +1 -1
  84. package/dist/dts/Boolean.d.ts +13 -13
  85. package/dist/dts/Brand.d.ts +3 -3
  86. package/dist/dts/Chunk.d.ts +3 -3
  87. package/dist/dts/Context.d.ts +15 -20
  88. package/dist/dts/Context.d.ts.map +1 -1
  89. package/dist/dts/Cron.d.ts +3 -6
  90. package/dist/dts/Cron.d.ts.map +1 -1
  91. package/dist/dts/Data.d.ts +10 -16
  92. package/dist/dts/Data.d.ts.map +1 -1
  93. package/dist/dts/Duration.d.ts +1 -1
  94. package/dist/dts/Effect.d.ts +120 -26
  95. package/dist/dts/Effect.d.ts.map +1 -1
  96. package/dist/dts/Either.d.ts +155 -64
  97. package/dist/dts/Either.d.ts.map +1 -1
  98. package/dist/dts/Equal.d.ts.map +1 -1
  99. package/dist/dts/FiberHandle.d.ts.map +1 -1
  100. package/dist/dts/FiberMap.d.ts.map +1 -1
  101. package/dist/dts/FiberSet.d.ts.map +1 -1
  102. package/dist/dts/Function.d.ts +4 -2
  103. package/dist/dts/Function.d.ts.map +1 -1
  104. package/dist/dts/Hash.d.ts.map +1 -1
  105. package/dist/dts/HashMap.d.ts +2 -2
  106. package/dist/dts/Iterable.d.ts +10 -13
  107. package/dist/dts/Iterable.d.ts.map +1 -1
  108. package/dist/dts/List.d.ts +2 -2
  109. package/dist/dts/Metric.d.ts +5 -7
  110. package/dist/dts/Metric.d.ts.map +1 -1
  111. package/dist/dts/Number.d.ts +20 -21
  112. package/dist/dts/Number.d.ts.map +1 -1
  113. package/dist/dts/Option.d.ts +245 -155
  114. package/dist/dts/Option.d.ts.map +1 -1
  115. package/dist/dts/Order.d.ts +1 -2
  116. package/dist/dts/Order.d.ts.map +1 -1
  117. package/dist/dts/Ordering.d.ts +2 -2
  118. package/dist/dts/Predicate.d.ts +9 -12
  119. package/dist/dts/Predicate.d.ts.map +1 -1
  120. package/dist/dts/Readable.d.ts.map +1 -1
  121. package/dist/dts/Record.d.ts +35 -47
  122. package/dist/dts/Record.d.ts.map +1 -1
  123. package/dist/dts/RegExp.d.ts +1 -1
  124. package/dist/dts/Request.d.ts +2 -2
  125. package/dist/dts/Request.d.ts.map +1 -1
  126. package/dist/dts/Stream.d.ts +136 -31
  127. package/dist/dts/Stream.d.ts.map +1 -1
  128. package/dist/dts/String.d.ts +81 -111
  129. package/dist/dts/String.d.ts.map +1 -1
  130. package/dist/dts/Struct.d.ts +13 -19
  131. package/dist/dts/Struct.d.ts.map +1 -1
  132. package/dist/dts/Subscribable.d.ts.map +1 -1
  133. package/dist/dts/Symbol.d.ts +3 -3
  134. package/dist/dts/TestAnnotation.d.ts.map +1 -1
  135. package/dist/dts/TestAnnotationMap.d.ts.map +1 -1
  136. package/dist/dts/TestAnnotations.d.ts.map +1 -1
  137. package/dist/dts/TestClock.d.ts +1 -5
  138. package/dist/dts/TestClock.d.ts.map +1 -1
  139. package/dist/dts/TestLive.d.ts.map +1 -1
  140. package/dist/dts/TestSized.d.ts.map +1 -1
  141. package/dist/dts/Trie.d.ts +28 -44
  142. package/dist/dts/Trie.d.ts.map +1 -1
  143. package/dist/dts/Types.d.ts +10 -10
  144. package/dist/dts/Utils.d.ts +19 -0
  145. package/dist/dts/Utils.d.ts.map +1 -1
  146. package/dist/dts/internal/core.d.ts.map +1 -1
  147. package/dist/dts/internal/doNotation.d.ts +2 -0
  148. package/dist/dts/internal/doNotation.d.ts.map +1 -0
  149. package/dist/dts/internal/stream.d.ts.map +1 -1
  150. package/dist/esm/Array.js +10 -13
  151. package/dist/esm/Array.js.map +1 -1
  152. package/dist/esm/BigDecimal.js +14 -17
  153. package/dist/esm/BigDecimal.js.map +1 -1
  154. package/dist/esm/BigInt.js +41 -46
  155. package/dist/esm/BigInt.js.map +1 -1
  156. package/dist/esm/Boolean.js +13 -13
  157. package/dist/esm/Brand.js +2 -2
  158. package/dist/esm/Chunk.js +3 -3
  159. package/dist/esm/Context.js +15 -20
  160. package/dist/esm/Context.js.map +1 -1
  161. package/dist/esm/Cron.js +3 -6
  162. package/dist/esm/Cron.js.map +1 -1
  163. package/dist/esm/Data.js +9 -15
  164. package/dist/esm/Data.js.map +1 -1
  165. package/dist/esm/Duration.js +1 -1
  166. package/dist/esm/Effect.js +101 -11
  167. package/dist/esm/Effect.js.map +1 -1
  168. package/dist/esm/Either.js +141 -61
  169. package/dist/esm/Either.js.map +1 -1
  170. package/dist/esm/Equal.js +26 -4
  171. package/dist/esm/Equal.js.map +1 -1
  172. package/dist/esm/FiberHandle.js.map +1 -1
  173. package/dist/esm/FiberMap.js.map +1 -1
  174. package/dist/esm/FiberSet.js.map +1 -1
  175. package/dist/esm/Function.js +2 -2
  176. package/dist/esm/Function.js.map +1 -1
  177. package/dist/esm/Hash.js +30 -13
  178. package/dist/esm/Hash.js.map +1 -1
  179. package/dist/esm/Iterable.js +10 -13
  180. package/dist/esm/Iterable.js.map +1 -1
  181. package/dist/esm/List.js +2 -2
  182. package/dist/esm/Metric.js +5 -7
  183. package/dist/esm/Metric.js.map +1 -1
  184. package/dist/esm/Number.js +20 -21
  185. package/dist/esm/Number.js.map +1 -1
  186. package/dist/esm/Option.js +249 -164
  187. package/dist/esm/Option.js.map +1 -1
  188. package/dist/esm/Order.js +1 -2
  189. package/dist/esm/Order.js.map +1 -1
  190. package/dist/esm/Ordering.js +2 -2
  191. package/dist/esm/Predicate.js +9 -12
  192. package/dist/esm/Predicate.js.map +1 -1
  193. package/dist/esm/Readable.js.map +1 -1
  194. package/dist/esm/Record.js +35 -47
  195. package/dist/esm/Record.js.map +1 -1
  196. package/dist/esm/RegExp.js +1 -1
  197. package/dist/esm/Request.js +2 -2
  198. package/dist/esm/Request.js.map +1 -1
  199. package/dist/esm/Stream.js +107 -6
  200. package/dist/esm/Stream.js.map +1 -1
  201. package/dist/esm/String.js +81 -111
  202. package/dist/esm/String.js.map +1 -1
  203. package/dist/esm/Struct.js +13 -19
  204. package/dist/esm/Struct.js.map +1 -1
  205. package/dist/esm/Subscribable.js.map +1 -1
  206. package/dist/esm/Symbol.js +3 -3
  207. package/dist/esm/TestAnnotation.js.map +1 -1
  208. package/dist/esm/TestAnnotationMap.js.map +1 -1
  209. package/dist/esm/TestAnnotations.js.map +1 -1
  210. package/dist/esm/TestClock.js.map +1 -1
  211. package/dist/esm/TestLive.js.map +1 -1
  212. package/dist/esm/TestSized.js.map +1 -1
  213. package/dist/esm/Trie.js +28 -44
  214. package/dist/esm/Trie.js.map +1 -1
  215. package/dist/esm/Utils.js +33 -0
  216. package/dist/esm/Utils.js.map +1 -1
  217. package/dist/esm/internal/core-effect.js +4 -11
  218. package/dist/esm/internal/core-effect.js.map +1 -1
  219. package/dist/esm/internal/core.js +16 -4
  220. package/dist/esm/internal/core.js.map +1 -1
  221. package/dist/esm/internal/doNotation.js +14 -0
  222. package/dist/esm/internal/doNotation.js.map +1 -0
  223. package/dist/esm/internal/groupBy.js.map +1 -1
  224. package/dist/esm/internal/stream.js +3 -7
  225. package/dist/esm/internal/stream.js.map +1 -1
  226. package/dist/esm/internal/version.js +1 -1
  227. package/package.json +1 -1
  228. package/src/Array.ts +10 -13
  229. package/src/BigDecimal.ts +14 -17
  230. package/src/BigInt.ts +41 -46
  231. package/src/Boolean.ts +13 -13
  232. package/src/Brand.ts +3 -3
  233. package/src/Chunk.ts +3 -3
  234. package/src/Context.ts +15 -20
  235. package/src/Cron.ts +3 -6
  236. package/src/Data.ts +10 -16
  237. package/src/Duration.ts +1 -1
  238. package/src/Effect.ts +122 -32
  239. package/src/Either.ts +161 -94
  240. package/src/Equal.ts +30 -9
  241. package/src/FiberHandle.ts +1 -1
  242. package/src/FiberMap.ts +1 -1
  243. package/src/FiberSet.ts +1 -1
  244. package/src/Function.ts +4 -2
  245. package/src/Hash.ts +30 -13
  246. package/src/HashMap.ts +2 -2
  247. package/src/Iterable.ts +10 -13
  248. package/src/List.ts +2 -2
  249. package/src/Metric.ts +5 -7
  250. package/src/Number.ts +20 -21
  251. package/src/Option.ts +250 -172
  252. package/src/Order.ts +1 -2
  253. package/src/Ordering.ts +2 -2
  254. package/src/Predicate.ts +9 -12
  255. package/src/Readable.ts +1 -1
  256. package/src/Record.ts +35 -47
  257. package/src/RegExp.ts +1 -1
  258. package/src/Request.ts +3 -3
  259. package/src/Stream.ts +137 -36
  260. package/src/String.ts +81 -111
  261. package/src/Struct.ts +13 -19
  262. package/src/Subscribable.ts +1 -1
  263. package/src/Symbol.ts +3 -3
  264. package/src/TestAnnotation.ts +1 -1
  265. package/src/TestAnnotationMap.ts +1 -1
  266. package/src/TestAnnotations.ts +1 -1
  267. package/src/TestClock.ts +1 -5
  268. package/src/TestLive.ts +1 -1
  269. package/src/TestSized.ts +1 -1
  270. package/src/Trie.ts +28 -44
  271. package/src/Types.ts +10 -10
  272. package/src/Utils.ts +40 -2
  273. package/src/internal/core-effect.ts +29 -45
  274. package/src/internal/core.ts +20 -4
  275. package/src/internal/doNotation.ts +77 -0
  276. package/src/internal/groupBy.ts +16 -16
  277. package/src/internal/stream.ts +34 -58
  278. package/src/internal/version.ts +1 -1
package/src/Either.ts CHANGED
@@ -7,12 +7,13 @@ import type { LazyArg } from "./Function.js"
7
7
  import { constNull, constUndefined, dual, identity } from "./Function.js"
8
8
  import type { TypeLambda } from "./HKT.js"
9
9
  import type { Inspectable } from "./Inspectable.js"
10
+ import * as doNotation from "./internal/doNotation.js"
10
11
  import * as either from "./internal/either.js"
11
12
  import type { Option } from "./Option.js"
12
13
  import type { Pipeable } from "./Pipeable.js"
13
14
  import type { Predicate, Refinement } from "./Predicate.js"
14
15
  import { isFunction } from "./Predicate.js"
15
- import type { Covariant, MergeRecord, NoInfer, NotFunction } from "./Types.js"
16
+ import type { Covariant, NoInfer, NotFunction } from "./Types.js"
16
17
  import type * as Unify from "./Unify.js"
17
18
  import * as Gen from "./Utils.js"
18
19
 
@@ -129,7 +130,7 @@ export const left: <L>(left: L) => Either<never, L> = either.left
129
130
  * the provided default as a `Left`.
130
131
  *
131
132
  * @example
132
- * import * as Either from 'effect/Either'
133
+ * import { Either } from "effect"
133
134
  *
134
135
  * assert.deepStrictEqual(Either.fromNullable(1, () => 'fallback'), Either.right(1))
135
136
  * assert.deepStrictEqual(Either.fromNullable(null, () => 'fallback'), Either.left('fallback'))
@@ -148,8 +149,7 @@ export const fromNullable: {
148
149
 
149
150
  /**
150
151
  * @example
151
- * import * as Either from 'effect/Either'
152
- * import * as Option from 'effect/Option'
152
+ * import { Either, Option } from "effect"
153
153
  *
154
154
  * assert.deepStrictEqual(Either.fromOption(Option.some(1), () => 'error'), Either.right(1))
155
155
  * assert.deepStrictEqual(Either.fromOption(Option.none(), () => 'error'), Either.left('error'))
@@ -208,11 +208,11 @@ export {
208
208
  * @param input - The value to test.
209
209
  *
210
210
  * @example
211
- * import { isEither, left, right } from 'effect/Either'
211
+ * import { Either } from "effect"
212
212
  *
213
- * assert.deepStrictEqual(isEither(right(1)), true)
214
- * assert.deepStrictEqual(isEither(left("a")), true)
215
- * assert.deepStrictEqual(isEither({ right: 1 }), false)
213
+ * assert.deepStrictEqual(Either.isEither(Either.right(1)), true)
214
+ * assert.deepStrictEqual(Either.isEither(Either.left("a")), true)
215
+ * assert.deepStrictEqual(Either.isEither({ right: 1 }), false)
216
216
  *
217
217
  * @category guards
218
218
  * @since 2.0.0
@@ -225,10 +225,10 @@ export const isEither: (input: unknown) => input is Either<unknown, unknown> = e
225
225
  * @param self - The `Either` to check.
226
226
  *
227
227
  * @example
228
- * import { isLeft, left, right } from 'effect/Either'
228
+ * import { Either } from "effect"
229
229
  *
230
- * assert.deepStrictEqual(isLeft(right(1)), false)
231
- * assert.deepStrictEqual(isLeft(left("a")), true)
230
+ * assert.deepStrictEqual(Either.isLeft(Either.right(1)), false)
231
+ * assert.deepStrictEqual(Either.isLeft(Either.left("a")), true)
232
232
  *
233
233
  * @category guards
234
234
  * @since 2.0.0
@@ -241,10 +241,10 @@ export const isLeft: <R, L>(self: Either<R, L>) => self is Left<L, R> = either.i
241
241
  * @param self - The `Either` to check.
242
242
  *
243
243
  * @example
244
- * import { isRight, left, right } from 'effect/Either'
244
+ * import { Either } from "effect"
245
245
  *
246
- * assert.deepStrictEqual(isRight(right(1)), true)
247
- * assert.deepStrictEqual(isRight(left("a")), false)
246
+ * assert.deepStrictEqual(Either.isRight(Either.right(1)), true)
247
+ * assert.deepStrictEqual(Either.isRight(Either.left("a")), false)
248
248
  *
249
249
  * @category guards
250
250
  * @since 2.0.0
@@ -257,11 +257,10 @@ export const isRight: <R, L>(self: Either<R, L>) => self is Right<L, R> = either
257
257
  * Alias of {@link toOption}.
258
258
  *
259
259
  * @example
260
- * import * as O from 'effect/Option'
261
- * import * as E from 'effect/Either'
260
+ * import { Either, Option } from "effect"
262
261
  *
263
- * assert.deepStrictEqual(E.getRight(E.right('ok')), O.some('ok'))
264
- * assert.deepStrictEqual(E.getRight(E.left('err')), O.none())
262
+ * assert.deepStrictEqual(Either.getRight(Either.right('ok')), Option.some('ok'))
263
+ * assert.deepStrictEqual(Either.getRight(Either.left('err')), Option.none())
265
264
  *
266
265
  * @category getters
267
266
  * @since 2.0.0
@@ -272,11 +271,10 @@ export const getRight: <R, L>(self: Either<R, L>) => Option<R> = either.getRight
272
271
  * Converts a `Either` to an `Option` discarding the value.
273
272
  *
274
273
  * @example
275
- * import * as O from 'effect/Option'
276
- * import * as E from 'effect/Either'
274
+ * import { Either, Option } from "effect"
277
275
  *
278
- * assert.deepStrictEqual(E.getLeft(E.right('ok')), O.none())
279
- * assert.deepStrictEqual(E.getLeft(E.left('err')), O.some('err'))
276
+ * assert.deepStrictEqual(Either.getLeft(Either.right('ok')), Option.none())
277
+ * assert.deepStrictEqual(Either.getLeft(Either.left('err')), Option.some('err'))
280
278
  *
281
279
  * @category getters
282
280
  * @since 2.0.0
@@ -360,16 +358,15 @@ export const map: {
360
358
  * if the value is a `Right` the inner value is applied to the `onRight` function.
361
359
  *
362
360
  * @example
363
- * import * as E from 'effect/Either'
364
- * import { pipe } from 'effect/Function'
361
+ * import { pipe, Either } from "effect"
365
362
  *
366
363
  * const onLeft = (strings: ReadonlyArray<string>): string => `strings: ${strings.join(', ')}`
367
364
  *
368
365
  * const onRight = (value: number): string => `Ok: ${value}`
369
366
  *
370
- * assert.deepStrictEqual(pipe(E.right(1), E.match({ onLeft, onRight })), 'Ok: 1')
367
+ * assert.deepStrictEqual(pipe(Either.right(1), Either.match({ onLeft, onRight })), 'Ok: 1')
371
368
  * assert.deepStrictEqual(
372
- * pipe(E.left(['string 1', 'string 2']), E.match({ onLeft, onRight })),
369
+ * pipe(Either.left(['string 1', 'string 2']), Either.match({ onLeft, onRight })),
373
370
  * 'strings: string 1, string 2'
374
371
  * )
375
372
  *
@@ -398,24 +395,23 @@ export const match: {
398
395
  * If the predicate fails, set the left value with the result of the provided function.
399
396
  *
400
397
  * @example
401
- * import * as E from 'effect/Either'
402
- * import { pipe } from 'effect/Function'
398
+ * import { pipe, Either } from "effect"
403
399
  *
404
400
  * const isPositive = (n: number): boolean => n > 0
405
401
  *
406
402
  * assert.deepStrictEqual(
407
403
  * pipe(
408
- * E.right(1),
409
- * E.filterOrLeft(isPositive, n => `${n} is not positive`)
404
+ * Either.right(1),
405
+ * Either.filterOrLeft(isPositive, n => `${n} is not positive`)
410
406
  * ),
411
- * E.right(1)
407
+ * Either.right(1)
412
408
  * )
413
409
  * assert.deepStrictEqual(
414
410
  * pipe(
415
- * E.right(0),
416
- * E.filterOrLeft(isPositive, n => `${n} is not positive`)
411
+ * Either.right(0),
412
+ * Either.filterOrLeft(isPositive, n => `${n} is not positive`)
417
413
  * ),
418
- * E.left("0 is not positive")
414
+ * Either.left("0 is not positive")
419
415
  * )
420
416
  *
421
417
  * @since 2.0.0
@@ -455,7 +451,7 @@ export const merge: <R, L>(self: Either<R, L>) => L | R = match({
455
451
  * Returns the wrapped value if it's a `Right` or a default value if is a `Left`.
456
452
  *
457
453
  * @example
458
- * import * as Either from 'effect/Either'
454
+ * import { Either } from "effect"
459
455
  *
460
456
  * assert.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + "!"), 1)
461
457
  * assert.deepStrictEqual(Either.getOrElse(Either.left("not a number"), (error) => error + "!"), "not a number!")
@@ -473,7 +469,7 @@ export const getOrElse: {
473
469
 
474
470
  /**
475
471
  * @example
476
- * import * as Either from 'effect/Either'
472
+ * import { Either } from "effect"
477
473
  *
478
474
  * assert.deepStrictEqual(Either.getOrNull(Either.right(1)), 1)
479
475
  * assert.deepStrictEqual(Either.getOrNull(Either.left("a")), null)
@@ -485,7 +481,7 @@ export const getOrNull: <R, L>(self: Either<R, L>) => R | null = getOrElse(const
485
481
 
486
482
  /**
487
483
  * @example
488
- * import * as Either from 'effect/Either'
484
+ * import { Either } from "effect"
489
485
  *
490
486
  * assert.deepStrictEqual(Either.getOrUndefined(Either.right(1)), 1)
491
487
  * assert.deepStrictEqual(Either.getOrUndefined(Either.left("a")), undefined)
@@ -504,13 +500,13 @@ export const getOrUndefined: <R, L>(self: Either<R, L>) => R | undefined = getOr
504
500
  * @param onLeft - A function that will be called if the `Either` is `Left`. It returns the error to be thrown.
505
501
  *
506
502
  * @example
507
- * import * as E from "effect/Either"
503
+ * import { Either } from "effect"
508
504
  *
509
505
  * assert.deepStrictEqual(
510
- * E.getOrThrowWith(E.right(1), () => new Error('Unexpected Left')),
506
+ * Either.getOrThrowWith(Either.right(1), () => new Error('Unexpected Left')),
511
507
  * 1
512
508
  * )
513
- * assert.throws(() => E.getOrThrowWith(E.left("error"), () => new Error('Unexpected Left')))
509
+ * assert.throws(() => Either.getOrThrowWith(Either.left("error"), () => new Error('Unexpected Left')))
514
510
  *
515
511
  * @category getters
516
512
  * @since 2.0.0
@@ -534,10 +530,10 @@ export const getOrThrowWith: {
534
530
  * @throws `Error("getOrThrow called on a Left")`
535
531
  *
536
532
  * @example
537
- * import * as E from "effect/Either"
533
+ * import { Either } from "effect"
538
534
  *
539
- * assert.deepStrictEqual(E.getOrThrow(E.right(1)), 1)
540
- * assert.throws(() => E.getOrThrow(E.left("error")))
535
+ * assert.deepStrictEqual(Either.getOrThrow(Either.right(1)), 1)
536
+ * assert.throws(() => Either.getOrThrow(Either.left("error")))
541
537
  *
542
538
  * @category getters
543
539
  * @since 2.0.0
@@ -644,7 +640,7 @@ export const ap: {
644
640
  * @param fields - the struct of `Either`s to be sequenced.
645
641
  *
646
642
  * @example
647
- * import * as Either from "effect/Either"
643
+ * import { Either } from "effect"
648
644
  *
649
645
  * assert.deepStrictEqual(Either.all([Either.right(1), Either.right(2)]), Either.right([1, 2]))
650
646
  * assert.deepStrictEqual(Either.all({ right: Either.right(1), b: Either.right("hello") }), Either.right({ right: 1, b: "hello" }))
@@ -742,77 +738,148 @@ export const gen: Gen.Gen<EitherTypeLambda, Gen.Adapter<EitherTypeLambda>> = (f)
742
738
  // -------------------------------------------------------------------------------------
743
739
 
744
740
  /**
745
- * @since 2.4.0
741
+ * The "do simulation" in allows you to write code in a more declarative style, similar to the "do notation" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.
742
+ *
743
+ * Here's how the do simulation works:
744
+ *
745
+ * 1. Start the do simulation using the `Do` value
746
+ * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values
747
+ * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
748
+ * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
749
+ *
750
+ * @see {@link bind}
751
+ * @see {@link bindTo}
752
+ * @see {@link let_ let}
753
+ *
754
+ * @example
755
+ * import { Either, pipe } from "effect"
756
+ *
757
+ * const result = pipe(
758
+ * Either.Do,
759
+ * Either.bind("x", () => Either.right(2)),
760
+ * Either.bind("y", () => Either.right(3)),
761
+ * Either.let("sum", ({ x, y }) => x + y)
762
+ * )
763
+ * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))
764
+ *
746
765
  * @category do notation
766
+ * @since 2.0.0
747
767
  */
748
768
  export const Do: Either<{}> = right({})
749
769
 
750
770
  /**
751
- * Binds an effectful value in a `do` scope
771
+ * The "do simulation" in allows you to write code in a more declarative style, similar to the "do notation" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.
772
+ *
773
+ * Here's how the do simulation works:
774
+ *
775
+ * 1. Start the do simulation using the `Do` value
776
+ * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values
777
+ * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
778
+ * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
779
+ *
780
+ * @see {@link Do}
781
+ * @see {@link bindTo}
782
+ * @see {@link let_ let}
783
+ *
784
+ * @example
785
+ * import { Either, pipe } from "effect"
786
+ *
787
+ * const result = pipe(
788
+ * Either.Do,
789
+ * Either.bind("x", () => Either.right(2)),
790
+ * Either.bind("y", () => Either.right(3)),
791
+ * Either.let("sum", ({ x, y }) => x + y)
792
+ * )
793
+ * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))
752
794
  *
753
- * @since 2.4.0
754
795
  * @category do notation
796
+ * @since 2.0.0
755
797
  */
756
798
  export const bind: {
757
- <N extends string, K, A, E2>(
758
- tag: Exclude<N, keyof K>,
759
- f: (_: K) => Either<A, E2>
760
- ): <E>(self: Either<K, E>) => Either<MergeRecord<K, { [k in N]: A }>, E2 | E>
761
- <K, E, N extends string, A, E2>(
762
- self: Either<E, K>,
763
- tag: Exclude<N, keyof K>,
764
- f: (_: K) => Either<A, E2>
765
- ): Either<MergeRecord<K, { [k in N]: A }>, E2 | E>
766
- } = dual(3, <K, E, N extends string, A, E2>(
767
- self: Either<K, E>,
768
- tag: Exclude<N, keyof K>,
769
- f: (_: K) => Either<A, E2>
770
- ): Either<MergeRecord<K, { [k in N]: A }>, E2 | E> =>
771
- flatMap(self, (k) =>
772
- map(
773
- f(k),
774
- (a): MergeRecord<K, { [k in N]: A }> => ({ ...k, [tag]: a } as any)
775
- )))
799
+ <N extends string, A extends object, B, L2>(
800
+ name: Exclude<N, keyof A>,
801
+ f: (a: A) => Either<B, L2>
802
+ ): <L1>(self: Either<A, L1>) => Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, L1 | L2>
803
+ <A extends object, L1, N extends string, B, L2>(
804
+ self: Either<A, L1>,
805
+ name: Exclude<N, keyof A>,
806
+ f: (a: A) => Either<B, L2>
807
+ ): Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, L1 | L2>
808
+ } = doNotation.bind<EitherTypeLambda>(map, flatMap)
776
809
 
777
810
  /**
811
+ * The "do simulation" in allows you to write code in a more declarative style, similar to the "do notation" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.
812
+ *
813
+ * Here's how the do simulation works:
814
+ *
815
+ * 1. Start the do simulation using the `Do` value
816
+ * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values
817
+ * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
818
+ * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
819
+ *
820
+ * @see {@link Do}
821
+ * @see {@link bind}
822
+ * @see {@link let_ let}
823
+ *
824
+ * @example
825
+ * import { Either, pipe } from "effect"
826
+ *
827
+ * const result = pipe(
828
+ * Either.Do,
829
+ * Either.bind("x", () => Either.right(2)),
830
+ * Either.bind("y", () => Either.right(3)),
831
+ * Either.let("sum", ({ x, y }) => x + y)
832
+ * )
833
+ * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))
834
+ *
778
835
  * @category do notation
779
- * @since 2.4.0
836
+ * @since 2.0.0
780
837
  */
781
838
  export const bindTo: {
782
- <N extends string>(tag: N): <A, E>(self: Either<A, E>) => Either<Record<N, A>, E>
783
- <A, E, N extends string>(self: Either<A, E>, tag: N): Either<Record<N, A>, E>
784
- } = dual(
785
- 2,
786
- <A, E, N extends string>(self: Either<A, E>, tag: N): Either<Record<N, A>, E> =>
787
- map(self, (a) => ({ [tag]: a } as Record<N, A>))
788
- )
839
+ <N extends string>(name: N): <R, L>(self: Either<R, L>) => Either<{ [K in N]: R }, L>
840
+ <R, L, N extends string>(self: Either<R, L>, name: N): Either<{ [K in N]: R }, L>
841
+ } = doNotation.bindTo<EitherTypeLambda>(map)
789
842
 
790
843
  const let_: {
791
- <N extends string, K, A>(
792
- tag: Exclude<N, keyof K>,
793
- f: (_: K) => A
794
- ): <E>(self: Either<K, E>) => Either<MergeRecord<K, { [k in N]: A }>, E>
795
- <K, E, N extends string, A>(
796
- self: Either<K, E>,
797
- tag: Exclude<N, keyof K>,
798
- f: (_: K) => A
799
- ): Either<MergeRecord<K, { [k in N]: A }>, E>
800
- } = dual(3, <K, E, N extends string, A>(
801
- self: Either<K, E>,
802
- tag: Exclude<N, keyof K>,
803
- f: (_: K) => A
804
- ): Either<MergeRecord<K, { [k in N]: A }>, E> =>
805
- map(
806
- self,
807
- (k): MergeRecord<K, { [k in N]: A }> => ({ ...k, [tag]: f(k) } as any)
808
- ))
844
+ <N extends string, R extends object, B>(
845
+ name: Exclude<N, keyof R>,
846
+ f: (r: R) => B
847
+ ): <L>(self: Either<R, L>) => Either<{ [K in N | keyof R]: K extends keyof R ? R[K] : B }, L>
848
+ <R extends object, L, N extends string, B>(
849
+ self: Either<R, L>,
850
+ name: Exclude<N, keyof R>,
851
+ f: (r: R) => B
852
+ ): Either<{ [K in N | keyof R]: K extends keyof R ? R[K] : B }, L>
853
+ } = doNotation.let_<EitherTypeLambda>(map)
809
854
 
810
855
  export {
811
856
  /**
812
- * Like bind for values
857
+ * The "do simulation" in allows you to write code in a more declarative style, similar to the "do notation" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.
858
+ *
859
+ * Here's how the do simulation works:
860
+ *
861
+ * 1. Start the do simulation using the `Do` value
862
+ * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values
863
+ * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
864
+ * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
865
+ *
866
+ * @see {@link Do}
867
+ * @see {@link bindTo}
868
+ * @see {@link bind}
869
+ *
870
+ * @example
871
+ * import { Either, pipe } from "effect"
872
+ *
873
+ * const result = pipe(
874
+ * Either.Do,
875
+ * Either.bind("x", () => Either.right(2)),
876
+ * Either.bind("y", () => Either.right(3)),
877
+ * Either.let("sum", ({ x, y }) => x + y)
878
+ * )
879
+ * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))
813
880
  *
814
- * @since 2.4.0
815
881
  * @category do notation
882
+ * @since 2.0.0
816
883
  */
817
884
  let_ as let
818
885
  }
package/src/Equal.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  import type { Equivalence } from "./Equivalence.js"
5
5
  import * as Hash from "./Hash.js"
6
6
  import { hasProperty } from "./Predicate.js"
7
+ import { structuralRegionState } from "./Utils.js"
7
8
 
8
9
  /**
9
10
  * @since 2.0.0
@@ -32,7 +33,7 @@ export function equals(): any {
32
33
  return compareBoth(arguments[0], arguments[1])
33
34
  }
34
35
 
35
- function compareBoth(self: unknown, that: unknown) {
36
+ function compareBoth(self: unknown, that: unknown): boolean {
36
37
  if (self === that) {
37
38
  return true
38
39
  }
@@ -40,16 +41,36 @@ function compareBoth(self: unknown, that: unknown) {
40
41
  if (selfType !== typeof that) {
41
42
  return false
42
43
  }
43
- if (
44
- (selfType === "object" || selfType === "function") &&
45
- self !== null &&
46
- that !== null
47
- ) {
48
- if (isEqual(self) && isEqual(that)) {
49
- return Hash.hash(self) === Hash.hash(that) && self[symbol](that)
44
+ if (selfType === "object" || selfType === "function") {
45
+ if (self !== null && that !== null) {
46
+ if (isEqual(self) && isEqual(that)) {
47
+ return Hash.hash(self) === Hash.hash(that) && self[symbol](that)
48
+ }
49
+ }
50
+ if (structuralRegionState.enabled) {
51
+ if (Array.isArray(self) && Array.isArray(that)) {
52
+ return self.length === that.length && self.every((v, i) => compareBoth(v, that[i]))
53
+ }
54
+ if (Object.getPrototypeOf(self) === Object.prototype && Object.getPrototypeOf(self) === Object.prototype) {
55
+ const keysSelf = Object.keys(self as any)
56
+ const keysThat = Object.keys(that as any)
57
+ if (keysSelf.length === keysThat.length) {
58
+ for (const key of keysSelf) {
59
+ // @ts-expect-error
60
+ if (!(key in that && compareBoth(self[key], that[key]))) {
61
+ return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false
62
+ }
63
+ }
64
+ return true
65
+ }
66
+ }
67
+ return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false
50
68
  }
51
69
  }
52
- return false
70
+
71
+ return structuralRegionState.enabled && structuralRegionState.tester
72
+ ? structuralRegionState.tester(self, that)
73
+ : false
53
74
  }
54
75
 
55
76
  /**
@@ -22,7 +22,7 @@ import * as Runtime from "./Runtime.js"
22
22
  * @since 2.0.0
23
23
  * @categories type ids
24
24
  */
25
- export const TypeId = Symbol.for("effect/FiberHandle")
25
+ export const TypeId: unique symbol = Symbol.for("effect/FiberHandle")
26
26
 
27
27
  /**
28
28
  * @since 2.0.0
package/src/FiberMap.ts CHANGED
@@ -24,7 +24,7 @@ import * as Runtime from "./Runtime.js"
24
24
  * @since 2.0.0
25
25
  * @categories type ids
26
26
  */
27
- export const TypeId = Symbol.for("effect/FiberMap")
27
+ export const TypeId: unique symbol = Symbol.for("effect/FiberMap")
28
28
 
29
29
  /**
30
30
  * @since 2.0.0
package/src/FiberSet.ts CHANGED
@@ -22,7 +22,7 @@ import * as Runtime from "./Runtime.js"
22
22
  * @since 2.0.0
23
23
  * @categories type ids
24
24
  */
25
- export const TypeId = Symbol.for("effect/FiberSet")
25
+ export const TypeId: unique symbol = Symbol.for("effect/FiberSet")
26
26
 
27
27
  /**
28
28
  * @since 2.0.0
package/src/Function.ts CHANGED
@@ -17,7 +17,7 @@ export interface FunctionTypeLambda extends TypeLambda {
17
17
  * @param input - The value to test.
18
18
  *
19
19
  * @example
20
- * import { isFunction } from 'effect/Predicate'
20
+ * import { isFunction } from "effect/Predicate"
21
21
  *
22
22
  * assert.deepStrictEqual(isFunction(isFunction), true)
23
23
  * assert.deepStrictEqual(isFunction("function"), false)
@@ -154,7 +154,7 @@ export const dual: {
154
154
  *
155
155
  * @example
156
156
  * import { pipe, apply } from "effect/Function"
157
- * import { length } from 'effect/String'
157
+ * import { length } from "effect/String"
158
158
  *
159
159
  * assert.deepStrictEqual(pipe(length, apply("hello")), 5)
160
160
  *
@@ -408,6 +408,8 @@ export const untupled = <A extends ReadonlyArray<unknown>, B>(f: (a: A) => B): (
408
408
  *
409
409
  * @example
410
410
  * import { pipe } from "effect/Function"
411
+ * // Alternatively, you can use the following import syntax, as `pipe` is also conveniently exported from the `effect` entry point:
412
+ * // import { pipe } from "effect"
411
413
  *
412
414
  * const length = (s: string): number => s.length
413
415
  * const double = (n: number): number => n * 2
package/src/Hash.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  import { pipe } from "./Function.js"
5
5
  import { globalValue } from "./GlobalValue.js"
6
6
  import { hasProperty } from "./Predicate.js"
7
- import { PCGRandom } from "./Utils.js"
7
+ import { PCGRandom, structuralRegionState } from "./Utils.js"
8
8
 
9
9
  /** @internal */
10
10
  const randomHashCache = globalValue(
@@ -72,6 +72,9 @@ export const hash: <A>(self: A) => number = <A>(self: A) => {
72
72
  * @category hashing
73
73
  */
74
74
  export const random: <A extends object>(self: A) => number = (self) => {
75
+ if (structuralRegionState.enabled === true) {
76
+ return 0
77
+ }
75
78
  if (!randomHashCache.has(self)) {
76
79
  randomHashCache.set(self, number(pcgr.integer(Number.MAX_SAFE_INTEGER)))
77
80
  }
@@ -168,22 +171,36 @@ export const cached: {
168
171
  if (arguments.length === 1) {
169
172
  const self = arguments[0] as object
170
173
  return function(hash: number) {
171
- Object.defineProperty(self, symbol, {
172
- value() {
173
- return hash
174
- },
175
- enumerable: false
176
- })
174
+ // @ts-expect-error
175
+ const original = self[symbol].bind(self)
176
+ if (structuralRegionState.enabled === false) {
177
+ Object.defineProperty(self, symbol, {
178
+ value() {
179
+ if (structuralRegionState.enabled === true) {
180
+ return original()
181
+ }
182
+ return hash
183
+ },
184
+ enumerable: false
185
+ })
186
+ }
177
187
  return hash
178
188
  } as any
179
189
  }
180
190
  const self = arguments[0] as object
181
191
  const hash = arguments[1] as number
182
- Object.defineProperty(self, symbol, {
183
- value() {
184
- return hash
185
- },
186
- enumerable: false
187
- })
192
+ // @ts-expect-error
193
+ const original = self[symbol].bind(self)
194
+ if (structuralRegionState.enabled === false) {
195
+ Object.defineProperty(self, symbol, {
196
+ value() {
197
+ if (structuralRegionState.enabled === true) {
198
+ return original()
199
+ }
200
+ return hash
201
+ },
202
+ enumerable: false
203
+ })
204
+ }
188
205
  return hash
189
206
  }
package/src/HashMap.ts CHANGED
@@ -40,7 +40,7 @@ export declare namespace HashMap {
40
40
  * This type-level utility extracts the key type `K` from a `HashMap<K, V>` type.
41
41
  *
42
42
  * @example
43
- * import * as HashMap from "effect/HashMap"
43
+ * import { HashMap } from "effect"
44
44
  *
45
45
  * declare const hm: HashMap.HashMap<string, number>
46
46
  *
@@ -55,7 +55,7 @@ export declare namespace HashMap {
55
55
  * This type-level utility extracts the value type `V` from a `HashMap<K, V>` type.
56
56
  *
57
57
  * @example
58
- * import * as HashMap from "effect/HashMap"
58
+ * import { HashMap } from "effect"
59
59
  *
60
60
  * declare const hm: HashMap.HashMap<string, number>
61
61
  *