@clayroach/effect 3.19.14-source-capture.6 → 3.19.14-source-capture.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.
Files changed (371) hide show
  1. package/dist/cjs/Utils.js +1 -1
  2. package/dist/cjs/Utils.js.map +1 -1
  3. package/dist/cjs/internal/clock.js +1 -1
  4. package/dist/cjs/internal/clock.js.map +1 -1
  5. package/dist/esm/Utils.js +1 -1
  6. package/dist/esm/Utils.js.map +1 -1
  7. package/dist/esm/internal/clock.js +1 -1
  8. package/dist/esm/internal/clock.js.map +1 -1
  9. package/package.json +1 -1
  10. package/src/Arbitrary.ts +0 -1101
  11. package/src/Array.ts +0 -3589
  12. package/src/BigDecimal.ts +0 -1349
  13. package/src/BigInt.ts +0 -643
  14. package/src/Boolean.ts +0 -287
  15. package/src/Brand.ts +0 -360
  16. package/src/Cache.ts +0 -281
  17. package/src/Cause.ts +0 -1555
  18. package/src/Channel.ts +0 -2355
  19. package/src/ChildExecutorDecision.ts +0 -146
  20. package/src/Chunk.ts +0 -1495
  21. package/src/Clock.ts +0 -111
  22. package/src/Config.ts +0 -542
  23. package/src/ConfigError.ts +0 -270
  24. package/src/ConfigProvider.ts +0 -333
  25. package/src/ConfigProviderPathPatch.ts +0 -100
  26. package/src/Console.ts +0 -226
  27. package/src/Context.ts +0 -585
  28. package/src/Cron.ts +0 -706
  29. package/src/Data.ts +0 -596
  30. package/src/DateTime.ts +0 -1686
  31. package/src/DefaultServices.ts +0 -34
  32. package/src/Deferred.ts +0 -301
  33. package/src/Differ.ts +0 -450
  34. package/src/Duration.ts +0 -1000
  35. package/src/Effect.ts +0 -14839
  36. package/src/Effectable.ts +0 -107
  37. package/src/Either.ts +0 -1040
  38. package/src/Encoding.ts +0 -195
  39. package/src/Equal.ts +0 -98
  40. package/src/Equivalence.ts +0 -235
  41. package/src/ExecutionPlan.ts +0 -308
  42. package/src/ExecutionStrategy.ts +0 -119
  43. package/src/Exit.ts +0 -467
  44. package/src/FastCheck.ts +0 -9
  45. package/src/Fiber.ts +0 -744
  46. package/src/FiberHandle.ts +0 -540
  47. package/src/FiberId.ts +0 -195
  48. package/src/FiberMap.ts +0 -656
  49. package/src/FiberRef.ts +0 -431
  50. package/src/FiberRefs.ts +0 -204
  51. package/src/FiberRefsPatch.ts +0 -105
  52. package/src/FiberSet.ts +0 -491
  53. package/src/FiberStatus.ts +0 -108
  54. package/src/Function.ts +0 -1222
  55. package/src/GlobalValue.ts +0 -53
  56. package/src/Graph.ts +0 -3732
  57. package/src/GroupBy.ts +0 -103
  58. package/src/HKT.ts +0 -45
  59. package/src/Hash.ts +0 -195
  60. package/src/HashMap.ts +0 -519
  61. package/src/HashRing.ts +0 -317
  62. package/src/HashSet.ts +0 -2346
  63. package/src/Inspectable.ts +0 -287
  64. package/src/Iterable.ts +0 -1119
  65. package/src/JSONSchema.ts +0 -1044
  66. package/src/KeyedPool.ts +0 -167
  67. package/src/Layer.ts +0 -1251
  68. package/src/LayerMap.ts +0 -436
  69. package/src/List.ts +0 -977
  70. package/src/LogLevel.ts +0 -285
  71. package/src/LogSpan.ts +0 -25
  72. package/src/Logger.ts +0 -702
  73. package/src/Mailbox.ts +0 -268
  74. package/src/ManagedRuntime.ts +0 -180
  75. package/src/Match.ts +0 -1477
  76. package/src/MergeDecision.ts +0 -95
  77. package/src/MergeState.ts +0 -172
  78. package/src/MergeStrategy.ts +0 -107
  79. package/src/Metric.ts +0 -780
  80. package/src/MetricBoundaries.ts +0 -69
  81. package/src/MetricHook.ts +0 -151
  82. package/src/MetricKey.ts +0 -224
  83. package/src/MetricKeyType.ts +0 -262
  84. package/src/MetricLabel.ts +0 -47
  85. package/src/MetricPair.ts +0 -71
  86. package/src/MetricPolling.ts +0 -148
  87. package/src/MetricRegistry.ts +0 -48
  88. package/src/MetricState.ts +0 -257
  89. package/src/Micro.ts +0 -4405
  90. package/src/ModuleVersion.ts +0 -18
  91. package/src/MutableHashMap.ts +0 -411
  92. package/src/MutableHashSet.ts +0 -706
  93. package/src/MutableList.ts +0 -297
  94. package/src/MutableQueue.ts +0 -227
  95. package/src/MutableRef.ts +0 -202
  96. package/src/NonEmptyIterable.ts +0 -32
  97. package/src/Number.ts +0 -1071
  98. package/src/Option.ts +0 -2170
  99. package/src/Order.ts +0 -373
  100. package/src/Ordering.ts +0 -111
  101. package/src/ParseResult.ts +0 -2031
  102. package/src/PartitionedSemaphore.ts +0 -200
  103. package/src/Pipeable.ts +0 -566
  104. package/src/Pool.ts +0 -204
  105. package/src/Predicate.ts +0 -1405
  106. package/src/Pretty.ts +0 -205
  107. package/src/PrimaryKey.ts +0 -23
  108. package/src/PubSub.ts +0 -182
  109. package/src/Queue.ts +0 -644
  110. package/src/Random.ts +0 -204
  111. package/src/RateLimiter.ts +0 -138
  112. package/src/RcMap.ts +0 -141
  113. package/src/RcRef.ts +0 -122
  114. package/src/Readable.ts +0 -93
  115. package/src/Record.ts +0 -1274
  116. package/src/RedBlackTree.ts +0 -421
  117. package/src/Redacted.ts +0 -144
  118. package/src/Ref.ts +0 -180
  119. package/src/RegExp.ts +0 -38
  120. package/src/Reloadable.ts +0 -127
  121. package/src/Request.ts +0 -347
  122. package/src/RequestBlock.ts +0 -118
  123. package/src/RequestResolver.ts +0 -366
  124. package/src/Resource.ts +0 -119
  125. package/src/Runtime.ts +0 -383
  126. package/src/RuntimeFlags.ts +0 -368
  127. package/src/RuntimeFlagsPatch.ts +0 -183
  128. package/src/STM.ts +0 -2045
  129. package/src/Schedule.ts +0 -2219
  130. package/src/ScheduleDecision.ts +0 -62
  131. package/src/ScheduleInterval.ts +0 -151
  132. package/src/ScheduleIntervals.ts +0 -122
  133. package/src/Scheduler.ts +0 -353
  134. package/src/Schema.ts +0 -10914
  135. package/src/SchemaAST.ts +0 -3043
  136. package/src/Scope.ts +0 -204
  137. package/src/ScopedCache.ts +0 -151
  138. package/src/ScopedRef.ts +0 -117
  139. package/src/Secret.ts +0 -88
  140. package/src/SingleProducerAsyncInput.ts +0 -67
  141. package/src/Sink.ts +0 -1461
  142. package/src/SortedMap.ts +0 -287
  143. package/src/SortedSet.ts +0 -390
  144. package/src/Stream.ts +0 -6468
  145. package/src/StreamEmit.ts +0 -136
  146. package/src/StreamHaltStrategy.ts +0 -123
  147. package/src/Streamable.ts +0 -45
  148. package/src/String.ts +0 -778
  149. package/src/Struct.ts +0 -243
  150. package/src/Subscribable.ts +0 -100
  151. package/src/SubscriptionRef.ts +0 -298
  152. package/src/Supervisor.ts +0 -240
  153. package/src/Symbol.ts +0 -29
  154. package/src/SynchronizedRef.ts +0 -270
  155. package/src/TArray.ts +0 -495
  156. package/src/TDeferred.ts +0 -100
  157. package/src/TMap.ts +0 -515
  158. package/src/TPriorityQueue.ts +0 -223
  159. package/src/TPubSub.ts +0 -200
  160. package/src/TQueue.ts +0 -432
  161. package/src/TRandom.ts +0 -129
  162. package/src/TReentrantLock.ts +0 -224
  163. package/src/TRef.ts +0 -178
  164. package/src/TSemaphore.ts +0 -129
  165. package/src/TSet.ts +0 -365
  166. package/src/TSubscriptionRef.ts +0 -192
  167. package/src/Take.ts +0 -258
  168. package/src/TestAnnotation.ts +0 -158
  169. package/src/TestAnnotationMap.ts +0 -119
  170. package/src/TestAnnotations.ts +0 -117
  171. package/src/TestClock.ts +0 -556
  172. package/src/TestConfig.ts +0 -47
  173. package/src/TestContext.ts +0 -36
  174. package/src/TestLive.ts +0 -53
  175. package/src/TestServices.ts +0 -390
  176. package/src/TestSized.ts +0 -55
  177. package/src/Tracer.ts +0 -198
  178. package/src/Trie.ts +0 -840
  179. package/src/Tuple.ts +0 -305
  180. package/src/Types.ts +0 -353
  181. package/src/Unify.ts +0 -113
  182. package/src/UpstreamPullRequest.ts +0 -117
  183. package/src/UpstreamPullStrategy.ts +0 -121
  184. package/src/Utils.ts +0 -809
  185. package/src/index.ts +0 -1561
  186. package/src/internal/array.ts +0 -8
  187. package/src/internal/blockedRequests.ts +0 -520
  188. package/src/internal/cache.ts +0 -733
  189. package/src/internal/cause.ts +0 -1050
  190. package/src/internal/channel/channelExecutor.ts +0 -1200
  191. package/src/internal/channel/channelState.ts +0 -134
  192. package/src/internal/channel/childExecutorDecision.ts +0 -96
  193. package/src/internal/channel/continuation.ts +0 -200
  194. package/src/internal/channel/mergeDecision.ts +0 -113
  195. package/src/internal/channel/mergeState.ts +0 -120
  196. package/src/internal/channel/mergeStrategy.ts +0 -72
  197. package/src/internal/channel/singleProducerAsyncInput.ts +0 -259
  198. package/src/internal/channel/subexecutor.ts +0 -229
  199. package/src/internal/channel/upstreamPullRequest.ts +0 -84
  200. package/src/internal/channel/upstreamPullStrategy.ts +0 -87
  201. package/src/internal/channel.ts +0 -2603
  202. package/src/internal/clock.ts +0 -95
  203. package/src/internal/completedRequestMap.ts +0 -9
  204. package/src/internal/concurrency.ts +0 -54
  205. package/src/internal/config.ts +0 -716
  206. package/src/internal/configError.ts +0 -304
  207. package/src/internal/configProvider/pathPatch.ts +0 -97
  208. package/src/internal/configProvider.ts +0 -799
  209. package/src/internal/console.ts +0 -153
  210. package/src/internal/context.ts +0 -337
  211. package/src/internal/core-effect.ts +0 -2293
  212. package/src/internal/core-stream.ts +0 -998
  213. package/src/internal/core.ts +0 -3273
  214. package/src/internal/data.ts +0 -36
  215. package/src/internal/dataSource.ts +0 -327
  216. package/src/internal/dateTime.ts +0 -1277
  217. package/src/internal/defaultServices/console.ts +0 -100
  218. package/src/internal/defaultServices.ts +0 -163
  219. package/src/internal/deferred.ts +0 -46
  220. package/src/internal/differ/chunkPatch.ts +0 -211
  221. package/src/internal/differ/contextPatch.ts +0 -232
  222. package/src/internal/differ/hashMapPatch.ts +0 -220
  223. package/src/internal/differ/hashSetPatch.ts +0 -176
  224. package/src/internal/differ/orPatch.ts +0 -311
  225. package/src/internal/differ/readonlyArrayPatch.ts +0 -210
  226. package/src/internal/differ.ts +0 -200
  227. package/src/internal/doNotation.ts +0 -80
  228. package/src/internal/effect/circular.ts +0 -905
  229. package/src/internal/effectable.ts +0 -131
  230. package/src/internal/either.ts +0 -110
  231. package/src/internal/encoding/base64.ts +0 -286
  232. package/src/internal/encoding/base64Url.ts +0 -29
  233. package/src/internal/encoding/common.ts +0 -51
  234. package/src/internal/encoding/hex.ts +0 -315
  235. package/src/internal/errors.ts +0 -7
  236. package/src/internal/executionPlan.ts +0 -114
  237. package/src/internal/executionStrategy.ts +0 -74
  238. package/src/internal/fiber.ts +0 -388
  239. package/src/internal/fiberId.ts +0 -267
  240. package/src/internal/fiberMessage.ts +0 -82
  241. package/src/internal/fiberRefs/patch.ts +0 -144
  242. package/src/internal/fiberRefs.ts +0 -297
  243. package/src/internal/fiberRuntime.ts +0 -3915
  244. package/src/internal/fiberScope.ts +0 -71
  245. package/src/internal/fiberStatus.ts +0 -119
  246. package/src/internal/groupBy.ts +0 -530
  247. package/src/internal/hashMap/array.ts +0 -49
  248. package/src/internal/hashMap/bitwise.ts +0 -32
  249. package/src/internal/hashMap/config.ts +0 -14
  250. package/src/internal/hashMap/keySet.ts +0 -8
  251. package/src/internal/hashMap/node.ts +0 -391
  252. package/src/internal/hashMap.ts +0 -586
  253. package/src/internal/hashSet.ts +0 -323
  254. package/src/internal/keyedPool.ts +0 -244
  255. package/src/internal/layer/circular.ts +0 -228
  256. package/src/internal/layer.ts +0 -1487
  257. package/src/internal/logSpan.ts +0 -20
  258. package/src/internal/logger-circular.ts +0 -24
  259. package/src/internal/logger.ts +0 -485
  260. package/src/internal/mailbox.ts +0 -561
  261. package/src/internal/managedRuntime/circular.ts +0 -6
  262. package/src/internal/managedRuntime.ts +0 -134
  263. package/src/internal/matcher.ts +0 -652
  264. package/src/internal/metric/boundaries.ts +0 -75
  265. package/src/internal/metric/hook.ts +0 -483
  266. package/src/internal/metric/key.ts +0 -167
  267. package/src/internal/metric/keyType.ts +0 -238
  268. package/src/internal/metric/label.ts +0 -41
  269. package/src/internal/metric/pair.ts +0 -48
  270. package/src/internal/metric/polling.ts +0 -149
  271. package/src/internal/metric/registry.ts +0 -187
  272. package/src/internal/metric/state.ts +0 -290
  273. package/src/internal/metric.ts +0 -577
  274. package/src/internal/opCodes/cause.ts +0 -35
  275. package/src/internal/opCodes/channel.ts +0 -83
  276. package/src/internal/opCodes/channelChildExecutorDecision.ts +0 -17
  277. package/src/internal/opCodes/channelMergeDecision.ts +0 -11
  278. package/src/internal/opCodes/channelMergeState.ts +0 -17
  279. package/src/internal/opCodes/channelMergeStrategy.ts +0 -11
  280. package/src/internal/opCodes/channelState.ts +0 -23
  281. package/src/internal/opCodes/channelUpstreamPullRequest.ts +0 -11
  282. package/src/internal/opCodes/channelUpstreamPullStrategy.ts +0 -11
  283. package/src/internal/opCodes/config.ts +0 -65
  284. package/src/internal/opCodes/configError.ts +0 -35
  285. package/src/internal/opCodes/continuation.ts +0 -11
  286. package/src/internal/opCodes/deferred.ts +0 -11
  287. package/src/internal/opCodes/effect.ts +0 -89
  288. package/src/internal/opCodes/layer.ts +0 -59
  289. package/src/internal/opCodes/streamHaltStrategy.ts +0 -23
  290. package/src/internal/option.ts +0 -80
  291. package/src/internal/pool.ts +0 -432
  292. package/src/internal/pubsub.ts +0 -1762
  293. package/src/internal/query.ts +0 -204
  294. package/src/internal/queue.ts +0 -766
  295. package/src/internal/random.ts +0 -161
  296. package/src/internal/rateLimiter.ts +0 -93
  297. package/src/internal/rcMap.ts +0 -285
  298. package/src/internal/rcRef.ts +0 -192
  299. package/src/internal/redBlackTree/iterator.ts +0 -200
  300. package/src/internal/redBlackTree/node.ts +0 -68
  301. package/src/internal/redBlackTree.ts +0 -1245
  302. package/src/internal/redacted.ts +0 -73
  303. package/src/internal/ref.ts +0 -171
  304. package/src/internal/reloadable.ts +0 -140
  305. package/src/internal/request.ts +0 -177
  306. package/src/internal/resource.ts +0 -76
  307. package/src/internal/ringBuffer.ts +0 -68
  308. package/src/internal/runtime.ts +0 -558
  309. package/src/internal/runtimeFlags.ts +0 -188
  310. package/src/internal/runtimeFlagsPatch.ts +0 -103
  311. package/src/internal/schedule/decision.ts +0 -47
  312. package/src/internal/schedule/interval.ts +0 -101
  313. package/src/internal/schedule/intervals.ts +0 -180
  314. package/src/internal/schedule.ts +0 -2199
  315. package/src/internal/schema/errors.ts +0 -191
  316. package/src/internal/schema/schemaId.ts +0 -106
  317. package/src/internal/schema/util.ts +0 -50
  318. package/src/internal/scopedCache.ts +0 -644
  319. package/src/internal/scopedRef.ts +0 -118
  320. package/src/internal/secret.ts +0 -89
  321. package/src/internal/singleShotGen.ts +0 -35
  322. package/src/internal/sink.ts +0 -2120
  323. package/src/internal/stack.ts +0 -10
  324. package/src/internal/stm/core.ts +0 -817
  325. package/src/internal/stm/entry.ts +0 -59
  326. package/src/internal/stm/journal.ts +0 -123
  327. package/src/internal/stm/opCodes/stm.ts +0 -71
  328. package/src/internal/stm/opCodes/stmState.ts +0 -17
  329. package/src/internal/stm/opCodes/strategy.ts +0 -17
  330. package/src/internal/stm/opCodes/tExit.ts +0 -29
  331. package/src/internal/stm/opCodes/tryCommit.ts +0 -11
  332. package/src/internal/stm/stm.ts +0 -1453
  333. package/src/internal/stm/stmState.ts +0 -136
  334. package/src/internal/stm/tArray.ts +0 -550
  335. package/src/internal/stm/tDeferred.ts +0 -81
  336. package/src/internal/stm/tExit.ts +0 -190
  337. package/src/internal/stm/tMap.ts +0 -824
  338. package/src/internal/stm/tPriorityQueue.ts +0 -267
  339. package/src/internal/stm/tPubSub.ts +0 -551
  340. package/src/internal/stm/tQueue.ts +0 -393
  341. package/src/internal/stm/tRandom.ts +0 -140
  342. package/src/internal/stm/tReentrantLock.ts +0 -352
  343. package/src/internal/stm/tRef.ts +0 -195
  344. package/src/internal/stm/tSemaphore.ts +0 -113
  345. package/src/internal/stm/tSet.ts +0 -259
  346. package/src/internal/stm/tSubscriptionRef.ts +0 -286
  347. package/src/internal/stm/tryCommit.ts +0 -34
  348. package/src/internal/stm/txnId.ts +0 -14
  349. package/src/internal/stm/versioned.ts +0 -4
  350. package/src/internal/stream/debounceState.ts +0 -57
  351. package/src/internal/stream/emit.ts +0 -123
  352. package/src/internal/stream/haltStrategy.ts +0 -94
  353. package/src/internal/stream/handoff.ts +0 -187
  354. package/src/internal/stream/handoffSignal.ts +0 -59
  355. package/src/internal/stream/pull.ts +0 -34
  356. package/src/internal/stream/sinkEndReason.ts +0 -30
  357. package/src/internal/stream/zipAllState.ts +0 -88
  358. package/src/internal/stream/zipChunksState.ts +0 -56
  359. package/src/internal/stream.ts +0 -8801
  360. package/src/internal/string-utils.ts +0 -107
  361. package/src/internal/subscriptionRef.ts +0 -138
  362. package/src/internal/supervisor/patch.ts +0 -190
  363. package/src/internal/supervisor.ts +0 -303
  364. package/src/internal/synchronizedRef.ts +0 -114
  365. package/src/internal/take.ts +0 -199
  366. package/src/internal/testing/sleep.ts +0 -27
  367. package/src/internal/testing/suspendedWarningData.ts +0 -85
  368. package/src/internal/testing/warningData.ts +0 -94
  369. package/src/internal/tracer.ts +0 -293
  370. package/src/internal/trie.ts +0 -722
  371. package/src/internal/version.ts +0 -7
package/src/Either.ts DELETED
@@ -1,1040 +0,0 @@
1
- /**
2
- * @since 2.0.0
3
- */
4
-
5
- import * as Equivalence from "./Equivalence.js"
6
- import type { LazyArg } from "./Function.js"
7
- import { constNull, constUndefined, dual, identity } from "./Function.js"
8
- import type { TypeLambda } from "./HKT.js"
9
- import type { Inspectable } from "./Inspectable.js"
10
- import * as doNotation from "./internal/doNotation.js"
11
- import * as either from "./internal/either.js"
12
- import * as option_ from "./internal/option.js"
13
- import type { Option } from "./Option.js"
14
- import type { Pipeable } from "./Pipeable.js"
15
- import type { Predicate, Refinement } from "./Predicate.js"
16
- import { isFunction } from "./Predicate.js"
17
- import type { Covariant, NoInfer, NotFunction } from "./Types.js"
18
- import type * as Unify from "./Unify.js"
19
- import * as Gen from "./Utils.js"
20
-
21
- /**
22
- * @category models
23
- * @since 2.0.0
24
- */
25
- export type Either<A, E = never> = Left<E, A> | Right<E, A>
26
-
27
- /**
28
- * @category symbols
29
- * @since 2.0.0
30
- */
31
- export const TypeId: unique symbol = either.TypeId
32
-
33
- /**
34
- * @category symbols
35
- * @since 2.0.0
36
- */
37
- export type TypeId = typeof TypeId
38
-
39
- // TODO(4.0): flip the order of the type parameters
40
- /**
41
- * @category models
42
- * @since 2.0.0
43
- */
44
- export interface Left<out E, out A> extends Pipeable, Inspectable {
45
- readonly _tag: "Left"
46
- readonly _op: "Left"
47
- readonly left: E
48
- readonly [TypeId]: {
49
- readonly _R: Covariant<A>
50
- readonly _L: Covariant<E>
51
- }
52
- [Unify.typeSymbol]?: unknown
53
- [Unify.unifySymbol]?: EitherUnify<this>
54
- [Unify.ignoreSymbol]?: EitherUnifyIgnore
55
- }
56
-
57
- // TODO(4.0): flip the order of the type parameters
58
- /**
59
- * @category models
60
- * @since 2.0.0
61
- */
62
- export interface Right<out E, out A> extends Pipeable, Inspectable {
63
- readonly _tag: "Right"
64
- readonly _op: "Right"
65
- readonly right: A
66
- readonly [TypeId]: {
67
- readonly _R: Covariant<A>
68
- readonly _L: Covariant<E>
69
- }
70
- [Unify.typeSymbol]?: unknown
71
- [Unify.unifySymbol]?: EitherUnify<this>
72
- [Unify.ignoreSymbol]?: EitherUnifyIgnore
73
- }
74
-
75
- /**
76
- * @category models
77
- * @since 2.0.0
78
- */
79
- export interface EitherUnify<A extends { [Unify.typeSymbol]?: any }> {
80
- Either?: () => A[Unify.typeSymbol] extends Either<infer R0, infer L0> | infer _ ? Either<R0, L0> : never
81
- }
82
-
83
- /**
84
- * @category models
85
- * @since 2.0.0
86
- */
87
- export interface EitherUnifyIgnore {}
88
-
89
- /**
90
- * @category type lambdas
91
- * @since 2.0.0
92
- */
93
- export interface EitherTypeLambda extends TypeLambda {
94
- readonly type: Either<this["Target"], this["Out1"]>
95
- }
96
-
97
- /**
98
- * @since 2.0.0
99
- */
100
- export declare namespace Either {
101
- /**
102
- * @since 2.0.0
103
- * @category type-level
104
- */
105
- export type Left<T extends Either<any, any>> = [T] extends [Either<infer _A, infer _E>] ? _E : never
106
- /**
107
- * @since 2.0.0
108
- * @category type-level
109
- */
110
- export type Right<T extends Either<any, any>> = [T] extends [Either<infer _A, infer _E>] ? _A : never
111
- }
112
-
113
- /**
114
- * Constructs a new `Either` holding a `Right` value. This usually represents a successful value due to the right bias
115
- * of this structure.
116
- *
117
- * @category constructors
118
- * @since 2.0.0
119
- */
120
- export const right: <A>(a: A) => Either<A> = either.right
121
-
122
- const void_: Either<void> = right(void 0)
123
- export {
124
- /**
125
- * @category constructors
126
- * @since 3.13.0
127
- */
128
- void_ as void
129
- }
130
-
131
- /**
132
- * Constructs a new `Either` holding a `Left` value. This usually represents a failure, due to the right-bias of this
133
- * structure.
134
- *
135
- * @category constructors
136
- * @since 2.0.0
137
- */
138
- export const left: <E>(e: E) => Either<never, E> = either.left
139
-
140
- /**
141
- * Takes a lazy default and a nullable value, if the value is not nully (`null` or `undefined`), turn it into a `Right`, if the value is nully use
142
- * the provided default as a `Left`.
143
- *
144
- * @example
145
- * ```ts
146
- * import * as assert from "node:assert"
147
- * import { Either } from "effect"
148
- *
149
- * assert.deepStrictEqual(Either.fromNullable(1, () => 'fallback'), Either.right(1))
150
- * assert.deepStrictEqual(Either.fromNullable(null, () => 'fallback'), Either.left('fallback'))
151
- * ```
152
- *
153
- * @category constructors
154
- * @since 2.0.0
155
- */
156
- export const fromNullable: {
157
- <A, E>(onNullable: (right: A) => E): (self: A) => Either<NonNullable<A>, E>
158
- <A, E>(self: A, onNullable: (right: A) => E): Either<NonNullable<A>, E>
159
- } = dual(
160
- 2,
161
- <A, E>(self: A, onNullable: (right: A) => E): Either<NonNullable<A>, E> =>
162
- self == null ? left(onNullable(self)) : right(self)
163
- )
164
-
165
- /**
166
- * @example
167
- * ```ts
168
- * import * as assert from "node:assert"
169
- * import { Either, Option } from "effect"
170
- *
171
- * assert.deepStrictEqual(Either.fromOption(Option.some(1), () => 'error'), Either.right(1))
172
- * assert.deepStrictEqual(Either.fromOption(Option.none(), () => 'error'), Either.left('error'))
173
- * ```
174
- *
175
- * @category constructors
176
- * @since 2.0.0
177
- */
178
- export const fromOption: {
179
- <E>(onNone: () => E): <A>(self: Option<A>) => Either<A, E>
180
- <A, E>(self: Option<A>, onNone: () => E): Either<A, E>
181
- } = either.fromOption
182
-
183
- const try_: {
184
- <A, E>(
185
- options: {
186
- readonly try: LazyArg<A>
187
- readonly catch: (error: unknown) => E
188
- }
189
- ): Either<A, E>
190
- <A>(evaluate: LazyArg<A>): Either<A, unknown>
191
- } = (<A, E>(
192
- evaluate: LazyArg<A> | {
193
- readonly try: LazyArg<A>
194
- readonly catch: (error: unknown) => E
195
- }
196
- ) => {
197
- if (isFunction(evaluate)) {
198
- try {
199
- return right(evaluate())
200
- } catch (e) {
201
- return left(e)
202
- }
203
- } else {
204
- try {
205
- return right(evaluate.try())
206
- } catch (e) {
207
- return left(evaluate.catch(e))
208
- }
209
- }
210
- }) as any
211
-
212
- export {
213
- /**
214
- * Imports a synchronous side-effect into a pure `Either` value, translating any
215
- * thrown exceptions into typed failed eithers creating with `Either.left`.
216
- *
217
- * @category constructors
218
- * @since 2.0.0
219
- */
220
- try_ as try
221
- }
222
-
223
- /**
224
- * Tests if a value is a `Either`.
225
- *
226
- * @example
227
- * ```ts
228
- * import * as assert from "node:assert"
229
- * import { Either } from "effect"
230
- *
231
- * assert.deepStrictEqual(Either.isEither(Either.right(1)), true)
232
- * assert.deepStrictEqual(Either.isEither(Either.left("a")), true)
233
- * assert.deepStrictEqual(Either.isEither({ right: 1 }), false)
234
- * ```
235
- *
236
- * @category guards
237
- * @since 2.0.0
238
- */
239
- export const isEither: (input: unknown) => input is Either<unknown, unknown> = either.isEither
240
-
241
- /**
242
- * Determine if a `Either` is a `Left`.
243
- *
244
- * @example
245
- * ```ts
246
- * import * as assert from "node:assert"
247
- * import { Either } from "effect"
248
- *
249
- * assert.deepStrictEqual(Either.isLeft(Either.right(1)), false)
250
- * assert.deepStrictEqual(Either.isLeft(Either.left("a")), true)
251
- * ```
252
- *
253
- * @category guards
254
- * @since 2.0.0
255
- */
256
- export const isLeft: <A, E>(self: Either<A, E>) => self is Left<E, A> = either.isLeft
257
-
258
- /**
259
- * Determine if a `Either` is a `Right`.
260
- *
261
- * @example
262
- * ```ts
263
- * import * as assert from "node:assert"
264
- * import { Either } from "effect"
265
- *
266
- * assert.deepStrictEqual(Either.isRight(Either.right(1)), true)
267
- * assert.deepStrictEqual(Either.isRight(Either.left("a")), false)
268
- * ```
269
- *
270
- * @category guards
271
- * @since 2.0.0
272
- */
273
- export const isRight: <A, E>(self: Either<A, E>) => self is Right<E, A> = either.isRight
274
-
275
- /**
276
- * Converts a `Either` to an `Option` discarding the `Left`.
277
- *
278
- * @example
279
- * ```ts
280
- * import * as assert from "node:assert"
281
- * import { Either, Option } from "effect"
282
- *
283
- * assert.deepStrictEqual(Either.getRight(Either.right('ok')), Option.some('ok'))
284
- * assert.deepStrictEqual(Either.getRight(Either.left('err')), Option.none())
285
- * ```
286
- *
287
- * @category getters
288
- * @since 2.0.0
289
- */
290
- export const getRight: <A, E>(self: Either<A, E>) => Option<A> = either.getRight
291
-
292
- /**
293
- * Converts a `Either` to an `Option` discarding the value.
294
- *
295
- * @example
296
- * ```ts
297
- * import * as assert from "node:assert"
298
- * import { Either, Option } from "effect"
299
- *
300
- * assert.deepStrictEqual(Either.getLeft(Either.right('ok')), Option.none())
301
- * assert.deepStrictEqual(Either.getLeft(Either.left('err')), Option.some('err'))
302
- * ```
303
- *
304
- * @category getters
305
- * @since 2.0.0
306
- */
307
- export const getLeft: <A, E>(self: Either<A, E>) => Option<E> = either.getLeft
308
-
309
- /**
310
- * @category equivalence
311
- * @since 2.0.0
312
- */
313
- export const getEquivalence = <A, E>({ left, right }: {
314
- right: Equivalence.Equivalence<A>
315
- left: Equivalence.Equivalence<E>
316
- }): Equivalence.Equivalence<Either<A, E>> =>
317
- Equivalence.make((x, y) =>
318
- isLeft(x) ?
319
- isLeft(y) && left(x.left, y.left) :
320
- isRight(y) && right(x.right, y.right)
321
- )
322
-
323
- /**
324
- * @category mapping
325
- * @since 2.0.0
326
- */
327
- export const mapBoth: {
328
- <E, E2, A, A2>(options: {
329
- readonly onLeft: (left: E) => E2
330
- readonly onRight: (right: A) => A2
331
- }): (self: Either<A, E>) => Either<A2, E2>
332
- <A, E, E2, A2>(self: Either<A, E>, options: {
333
- readonly onLeft: (left: E) => E2
334
- readonly onRight: (right: A) => A2
335
- }): Either<A2, E2>
336
- } = dual(
337
- 2,
338
- <A, E, E2, A2>(self: Either<A, E>, { onLeft, onRight }: {
339
- readonly onLeft: (left: E) => E2
340
- readonly onRight: (right: A) => A2
341
- }): Either<A2, E2> => isLeft(self) ? left(onLeft(self.left)) : right(onRight(self.right))
342
- )
343
-
344
- /**
345
- * Maps the `Left` side of an `Either` value to a new `Either` value.
346
- *
347
- * @category mapping
348
- * @since 2.0.0
349
- */
350
- export const mapLeft: {
351
- <E, E2>(f: (left: E) => E2): <A>(self: Either<A, E>) => Either<A, E2>
352
- <A, E, E2>(self: Either<A, E>, f: (left: E) => E2): Either<A, E2>
353
- } = dual(
354
- 2,
355
- <A, E, E2>(self: Either<A, E>, f: (left: E) => E2): Either<A, E2> =>
356
- isLeft(self) ? left(f(self.left)) : right(self.right)
357
- )
358
-
359
- /**
360
- * Maps the `Right` side of an `Either` value to a new `Either` value.
361
- *
362
- * @category mapping
363
- * @since 2.0.0
364
- */
365
- export const map: {
366
- <A, A2>(f: (right: A) => A2): <E>(self: Either<A, E>) => Either<A2, E>
367
- <A, E, A2>(self: Either<A, E>, f: (right: A) => A2): Either<A2, E>
368
- } = dual(
369
- 2,
370
- <A, E, A2>(self: Either<A, E>, f: (right: A) => A2): Either<A2, E> =>
371
- isRight(self) ? right(f(self.right)) : left(self.left)
372
- )
373
-
374
- /**
375
- * Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the `onLeft function,
376
- * if the value is a `Right` the inner value is applied to the `onRight` function.
377
- *
378
- * @example
379
- * ```ts
380
- * import * as assert from "node:assert"
381
- * import { pipe, Either } from "effect"
382
- *
383
- * const onLeft = (strings: ReadonlyArray<string>): string => `strings: ${strings.join(', ')}`
384
- *
385
- * const onRight = (value: number): string => `Ok: ${value}`
386
- *
387
- * assert.deepStrictEqual(pipe(Either.right(1), Either.match({ onLeft, onRight })), 'Ok: 1')
388
- * assert.deepStrictEqual(
389
- * pipe(Either.left(['string 1', 'string 2']), Either.match({ onLeft, onRight })),
390
- * 'strings: string 1, string 2'
391
- * )
392
- * ```
393
- *
394
- * @category pattern matching
395
- * @since 2.0.0
396
- */
397
- export const match: {
398
- <E, B, A, C = B>(options: {
399
- readonly onLeft: (left: E) => B
400
- readonly onRight: (right: A) => C
401
- }): (self: Either<A, E>) => B | C
402
- <A, E, B, C = B>(self: Either<A, E>, options: {
403
- readonly onLeft: (left: E) => B
404
- readonly onRight: (right: A) => C
405
- }): B | C
406
- } = dual(
407
- 2,
408
- <A, E, B, C = B>(self: Either<A, E>, { onLeft, onRight }: {
409
- readonly onLeft: (left: E) => B
410
- readonly onRight: (right: A) => C
411
- }): B | C => isLeft(self) ? onLeft(self.left) : onRight(self.right)
412
- )
413
-
414
- /**
415
- * Transforms a `Predicate` function into a `Right` of the input value if the predicate returns `true`
416
- * or `Left` of the result of the provided function if the predicate returns false
417
- *
418
- * @example
419
- * ```ts
420
- * import * as assert from "node:assert"
421
- * import { pipe, Either } from "effect"
422
- *
423
- * const isPositive = (n: number): boolean => n > 0
424
- * const isPositiveEither = Either.liftPredicate(isPositive, n => `${n} is not positive`)
425
- *
426
- * assert.deepStrictEqual(
427
- * isPositiveEither(1),
428
- * Either.right(1)
429
- * )
430
- * assert.deepStrictEqual(
431
- * isPositiveEither(0),
432
- * Either.left("0 is not positive")
433
- * )
434
- * ```
435
- *
436
- * @category lifting
437
- * @since 3.4.0
438
- */
439
- export const liftPredicate: {
440
- <A, B extends A, E>(refinement: Refinement<A, B>, orLeftWith: (a: A) => E): (a: A) => Either<B, E>
441
- <B extends A, E, A = B>(
442
- predicate: Predicate<A>,
443
- orLeftWith: (a: A) => E
444
- ): (a: B) => Either<B, E>
445
- <A, E, B extends A>(
446
- self: A,
447
- refinement: Refinement<A, B>,
448
- orLeftWith: (a: A) => E
449
- ): Either<B, E>
450
- <B extends A, E, A = B>(
451
- self: B,
452
- predicate: Predicate<A>,
453
- orLeftWith: (a: A) => E
454
- ): Either<B, E>
455
- } = dual(
456
- 3,
457
- <A, E>(a: A, predicate: Predicate<A>, orLeftWith: (a: A) => E): Either<A, E> =>
458
- predicate(a) ? right(a) : left(orLeftWith(a))
459
- )
460
-
461
- /**
462
- * Filter the right value with the provided function.
463
- * If the predicate fails, set the left value with the result of the provided function.
464
- *
465
- * @example
466
- * ```ts
467
- * import * as assert from "node:assert"
468
- * import { pipe, Either } from "effect"
469
- *
470
- * const isPositive = (n: number): boolean => n > 0
471
- *
472
- * assert.deepStrictEqual(
473
- * pipe(
474
- * Either.right(1),
475
- * Either.filterOrLeft(isPositive, n => `${n} is not positive`)
476
- * ),
477
- * Either.right(1)
478
- * )
479
- * assert.deepStrictEqual(
480
- * pipe(
481
- * Either.right(0),
482
- * Either.filterOrLeft(isPositive, n => `${n} is not positive`)
483
- * ),
484
- * Either.left("0 is not positive")
485
- * )
486
- * ```
487
- *
488
- * @since 2.0.0
489
- * @category filtering & conditionals
490
- */
491
- export const filterOrLeft: {
492
- <A, B extends A, E2>(
493
- refinement: Refinement<NoInfer<A>, B>,
494
- orLeftWith: (right: NoInfer<A>) => E2
495
- ): <E>(self: Either<A, E>) => Either<B, E2 | E>
496
- <A, E2>(
497
- predicate: Predicate<NoInfer<A>>,
498
- orLeftWith: (right: NoInfer<A>) => E2
499
- ): <E>(self: Either<A, E>) => Either<A, E2 | E>
500
- <A, E, B extends A, E2>(
501
- self: Either<A, E>,
502
- refinement: Refinement<A, B>,
503
- orLeftWith: (right: A) => E2
504
- ): Either<B, E | E2>
505
- <A, E, E2>(self: Either<A, E>, predicate: Predicate<A>, orLeftWith: (right: A) => E2): Either<A, E | E2>
506
- } = dual(3, <A, E, E2>(
507
- self: Either<A, E>,
508
- predicate: Predicate<A>,
509
- orLeftWith: (right: A) => E2
510
- ): Either<A, E | E2> => flatMap(self, (r) => predicate(r) ? right(r) : left(orLeftWith(r))))
511
-
512
- /**
513
- * @category getters
514
- * @since 2.0.0
515
- */
516
- export const merge: <A, E>(self: Either<A, E>) => E | A = match({
517
- onLeft: identity,
518
- onRight: identity
519
- })
520
-
521
- /**
522
- * Returns the wrapped value if it's a `Right` or a default value if is a `Left`.
523
- *
524
- * @example
525
- * ```ts
526
- * import * as assert from "node:assert"
527
- * import { Either } from "effect"
528
- *
529
- * assert.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + "!"), 1)
530
- * assert.deepStrictEqual(Either.getOrElse(Either.left("not a number"), (error) => error + "!"), "not a number!")
531
- * ```
532
- *
533
- * @category getters
534
- * @since 2.0.0
535
- */
536
- export const getOrElse: {
537
- <E, A2>(onLeft: (left: E) => A2): <A>(self: Either<A, E>) => A2 | A
538
- <A, E, A2>(self: Either<A, E>, onLeft: (left: E) => A2): A | A2
539
- } = dual(
540
- 2,
541
- <A, E, A2>(self: Either<A, E>, onLeft: (left: E) => A2): A | A2 => isLeft(self) ? onLeft(self.left) : self.right
542
- )
543
-
544
- /**
545
- * @example
546
- * ```ts
547
- * import * as assert from "node:assert"
548
- * import { Either } from "effect"
549
- *
550
- * assert.deepStrictEqual(Either.getOrNull(Either.right(1)), 1)
551
- * assert.deepStrictEqual(Either.getOrNull(Either.left("a")), null)
552
- * ```
553
- *
554
- * @category getters
555
- * @since 2.0.0
556
- */
557
- export const getOrNull: <A, E>(self: Either<A, E>) => A | null = getOrElse(constNull)
558
-
559
- /**
560
- * @example
561
- * ```ts
562
- * import * as assert from "node:assert"
563
- * import { Either } from "effect"
564
- *
565
- * assert.deepStrictEqual(Either.getOrUndefined(Either.right(1)), 1)
566
- * assert.deepStrictEqual(Either.getOrUndefined(Either.left("a")), undefined)
567
- * ```
568
- *
569
- * @category getters
570
- * @since 2.0.0
571
- */
572
- export const getOrUndefined: <A, E>(self: Either<A, E>) => A | undefined = getOrElse(constUndefined)
573
-
574
- /**
575
- * Extracts the value of an `Either` or throws if the `Either` is `Left`.
576
- *
577
- * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.
578
- *
579
- * @example
580
- * ```ts
581
- * import * as assert from "node:assert"
582
- * import { Either } from "effect"
583
- *
584
- * assert.deepStrictEqual(
585
- * Either.getOrThrowWith(Either.right(1), () => new Error('Unexpected Left')),
586
- * 1
587
- * )
588
- * assert.throws(() => Either.getOrThrowWith(Either.left("error"), () => new Error('Unexpected Left')))
589
- * ```
590
- *
591
- * @category getters
592
- * @since 2.0.0
593
- */
594
- export const getOrThrowWith: {
595
- <E>(onLeft: (left: E) => unknown): <A>(self: Either<A, E>) => A
596
- <A, E>(self: Either<A, E>, onLeft: (left: E) => unknown): A
597
- } = dual(2, <A, E>(self: Either<A, E>, onLeft: (left: E) => unknown): A => {
598
- if (isRight(self)) {
599
- return self.right
600
- }
601
- throw onLeft(self.left)
602
- })
603
-
604
- // TODO(4.0): by default should throw `L` (i.e getOrThrowWith with the identity function)
605
- /**
606
- * Extracts the value of an `Either` or throws if the `Either` is `Left`.
607
- *
608
- * The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.
609
- *
610
- * @example
611
- * ```ts
612
- * import * as assert from "node:assert"
613
- * import { Either } from "effect"
614
- *
615
- * assert.deepStrictEqual(Either.getOrThrow(Either.right(1)), 1)
616
- * assert.throws(() => Either.getOrThrow(Either.left("error")))
617
- * ```
618
- *
619
- * @throws `Error("getOrThrow called on a Left")`
620
- *
621
- * @category getters
622
- * @since 2.0.0
623
- */
624
- export const getOrThrow: <A, E>(self: Either<A, E>) => A = getOrThrowWith(() =>
625
- new Error("getOrThrow called on a Left")
626
- )
627
-
628
- /**
629
- * Returns `self` if it is a `Right` or `that` otherwise.
630
- *
631
- * @category error handling
632
- * @since 2.0.0
633
- */
634
- export const orElse: {
635
- <E, A2, E2>(that: (left: E) => Either<A2, E2>): <A>(self: Either<A, E>) => Either<A | A2, E2>
636
- <A, E, A2, E2>(self: Either<A, E>, that: (left: E) => Either<A2, E2>): Either<A | A2, E2>
637
- } = dual(
638
- 2,
639
- <A, E, A2, E2>(self: Either<A, E>, that: (left: E) => Either<A2, E2>): Either<A | A2, E2> =>
640
- isLeft(self) ? that(self.left) : right(self.right)
641
- )
642
-
643
- /**
644
- * @category sequencing
645
- * @since 2.0.0
646
- */
647
- export const flatMap: {
648
- <A, A2, E2>(f: (right: A) => Either<A2, E2>): <E>(self: Either<A, E>) => Either<A2, E | E2>
649
- <A, E, A2, E2>(self: Either<A, E>, f: (right: A) => Either<A2, E2>): Either<A2, E | E2>
650
- } = dual(
651
- 2,
652
- <A, E, A2, E2>(self: Either<A, E>, f: (right: A) => Either<A2, E2>): Either<A2, E | E2> =>
653
- isLeft(self) ? left(self.left) : f(self.right)
654
- )
655
-
656
- /**
657
- * Executes a sequence of two `Either`s. The second `Either` can be dependent on the result of the first `Either`.
658
- *
659
- * @category sequencing
660
- * @since 2.0.0
661
- */
662
- export const andThen: {
663
- <A, A2, E2>(f: (right: A) => Either<A2, E2>): <E>(self: Either<A, E>) => Either<A2, E | E2>
664
- <A2, E2>(f: Either<A2, E2>): <E, A>(self: Either<A, E>) => Either<A2, E | E2>
665
- <A, A2>(f: (right: A) => A2): <E>(self: Either<A, E>) => Either<A2, E>
666
- <A2>(right: NotFunction<A2>): <A, E>(self: Either<A, E>) => Either<A2, E>
667
- <A, E, A2, E2>(self: Either<A, E>, f: (right: A) => Either<A2, E2>): Either<A2, E | E2>
668
- <A, E, A2, E2>(self: Either<A, E>, f: Either<A2, E2>): Either<A2, E | E2>
669
- <A, E, A2>(self: Either<A, E>, f: (right: A) => A2): Either<A2, E>
670
- <A, E, A2>(self: Either<A, E>, f: NotFunction<A2>): Either<A2, E>
671
- } = dual(
672
- 2,
673
- <A, E, A2, E2>(self: Either<A, E>, f: (right: A) => Either<A2, E2> | Either<A2, E2>): Either<A2, E | E2> =>
674
- flatMap(self, (a) => {
675
- const b = isFunction(f) ? f(a) : f
676
- return isEither(b) ? b : right(b)
677
- })
678
- )
679
-
680
- /**
681
- * @category zipping
682
- * @since 2.0.0
683
- */
684
- export const zipWith: {
685
- <A2, E2, A, B>(
686
- that: Either<A2, E2>,
687
- f: (right: A, right2: A2) => B
688
- ): <E>(self: Either<A, E>) => Either<B, E2 | E>
689
- <A, E, A2, E2, B>(
690
- self: Either<A, E>,
691
- that: Either<A2, E2>,
692
- f: (right: A, right2: A2) => B
693
- ): Either<B, E | E2>
694
- } = dual(
695
- 3,
696
- <A, E, A2, E2, B>(self: Either<A, E>, that: Either<A2, E2>, f: (right: A, right2: A2) => B): Either<B, E | E2> =>
697
- flatMap(self, (r) => map(that, (r2) => f(r, r2)))
698
- )
699
-
700
- /**
701
- * @category combining
702
- * @since 2.0.0
703
- */
704
- export const ap: {
705
- <A, E2>(that: Either<A, E2>): <A2, E>(self: Either<(right: A) => A2, E>) => Either<A2, E | E2>
706
- <A, A2, E, E2>(self: Either<(right: A) => A2, E>, that: Either<A, E2>): Either<A2, E | E2>
707
- } = dual(
708
- 2,
709
- <A, E, A2, E2>(self: Either<(right: A) => A2, E>, that: Either<A, E2>): Either<A2, E | E2> =>
710
- zipWith(self, that, (f, a) => f(a))
711
- )
712
-
713
- /**
714
- * Takes a structure of `Either`s and returns an `Either` of values with the same structure.
715
- *
716
- * - If a tuple is supplied, then the returned `Either` will contain a tuple with the same length.
717
- * - If a struct is supplied, then the returned `Either` will contain a struct with the same keys.
718
- * - If an iterable is supplied, then the returned `Either` will contain an array.
719
- *
720
- * @example
721
- * ```ts
722
- * import * as assert from "node:assert"
723
- * import { Either } from "effect"
724
- *
725
- * assert.deepStrictEqual(Either.all([Either.right(1), Either.right(2)]), Either.right([1, 2]))
726
- * assert.deepStrictEqual(Either.all({ right: Either.right(1), b: Either.right("hello") }), Either.right({ right: 1, b: "hello" }))
727
- * assert.deepStrictEqual(Either.all({ right: Either.right(1), b: Either.left("error") }), Either.left("error"))
728
- * ```
729
- *
730
- * @category combining
731
- * @since 2.0.0
732
- */
733
- // @ts-expect-error
734
- export const all: <const I extends Iterable<Either<any, any>> | Record<string, Either<any, any>>>(
735
- input: I
736
- ) => [I] extends [ReadonlyArray<Either<any, any>>] ? Either<
737
- { -readonly [K in keyof I]: [I[K]] extends [Either<infer A, any>] ? A : never },
738
- I[number] extends never ? never : [I[number]] extends [Either<any, infer E>] ? E : never
739
- >
740
- : [I] extends [Iterable<Either<infer A, infer E>>] ? Either<Array<A>, E>
741
- : Either<
742
- { -readonly [K in keyof I]: [I[K]] extends [Either<infer A, any>] ? A : never },
743
- I[keyof I] extends never ? never : [I[keyof I]] extends [Either<any, infer E>] ? E : never
744
- > = (
745
- input: Iterable<Either<any, any>> | Record<string, Either<any, any>>
746
- ): Either<any, any> => {
747
- if (Symbol.iterator in input) {
748
- const out: Array<Either<any, any>> = []
749
- for (const e of input) {
750
- if (isLeft(e)) {
751
- return e
752
- }
753
- out.push(e.right)
754
- }
755
- return right(out)
756
- }
757
-
758
- const out: Record<string, any> = {}
759
- for (const key of Object.keys(input)) {
760
- const e = input[key]
761
- if (isLeft(e)) {
762
- return e
763
- }
764
- out[key] = e.right
765
- }
766
- return right(out)
767
- }
768
-
769
- /**
770
- * Returns an `Either` that swaps the error/success cases. This allows you to
771
- * use all methods on the error channel, possibly before flipping back.
772
- *
773
- * @since 2.0.0
774
- * @category mapping
775
- */
776
- export const flip = <A, E>(self: Either<A, E>): Either<E, A> => isLeft(self) ? right(self.left) : left(self.right)
777
-
778
- const adapter = Gen.adapter<EitherTypeLambda>()
779
-
780
- /**
781
- * @category generators
782
- * @since 2.0.0
783
- */
784
- export const gen: Gen.Gen<EitherTypeLambda, Gen.Adapter<EitherTypeLambda>> = (...args) => {
785
- const f = args.length === 1 ? args[0] : args[1].bind(args[0])
786
- const iterator = f(adapter)
787
- let state: IteratorResult<any> = iterator.next()
788
- while (!state.done) {
789
- const current = Gen.isGenKind(state.value)
790
- ? state.value.value
791
- : Gen.yieldWrapGet(state.value)
792
- if (isLeft(current)) {
793
- return current
794
- }
795
- state = iterator.next(current.right as never)
796
- }
797
- return right(state.value) as any
798
- }
799
-
800
- // -------------------------------------------------------------------------------------
801
- // do notation
802
- // -------------------------------------------------------------------------------------
803
-
804
- /**
805
- * The "do simulation" in Effect 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`.
806
- *
807
- * Here's how the do simulation works:
808
- *
809
- * 1. Start the do simulation using the `Do` value
810
- * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values
811
- * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
812
- * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
813
- *
814
- * @example
815
- * ```ts
816
- * import * as assert from "node:assert"
817
- * import { Either, pipe } from "effect"
818
- *
819
- * const result = pipe(
820
- * Either.Do,
821
- * Either.bind("x", () => Either.right(2)),
822
- * Either.bind("y", () => Either.right(3)),
823
- * Either.let("sum", ({ x, y }) => x + y)
824
- * )
825
- * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))
826
- * ```
827
- *
828
- * @see {@link bind}
829
- * @see {@link bindTo}
830
- * @see {@link let_ let}
831
- *
832
- * @category do notation
833
- * @since 2.0.0
834
- */
835
- export const Do: Either<{}> = right({})
836
-
837
- /**
838
- * The "do simulation" in Effect 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`.
839
- *
840
- * Here's how the do simulation works:
841
- *
842
- * 1. Start the do simulation using the `Do` value
843
- * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values
844
- * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
845
- * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
846
- *
847
- * @example
848
- * ```ts
849
- * import * as assert from "node:assert"
850
- * import { Either, pipe } from "effect"
851
- *
852
- * const result = pipe(
853
- * Either.Do,
854
- * Either.bind("x", () => Either.right(2)),
855
- * Either.bind("y", () => Either.right(3)),
856
- * Either.let("sum", ({ x, y }) => x + y)
857
- * )
858
- * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))
859
- * ```
860
- *
861
- * @see {@link Do}
862
- * @see {@link bindTo}
863
- * @see {@link let_ let}
864
- *
865
- * @category do notation
866
- * @since 2.0.0
867
- */
868
- export const bind: {
869
- <N extends string, A extends object, B, E2>(
870
- name: Exclude<N, keyof A>,
871
- f: (a: NoInfer<A>) => Either<B, E2>
872
- ): <E>(self: Either<A, E>) => Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, E | E2>
873
- <A extends object, E, N extends string, B, E2>(
874
- self: Either<A, E>,
875
- name: Exclude<N, keyof A>,
876
- f: (a: NoInfer<A>) => Either<B, E2>
877
- ): Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, E | E2>
878
- } = doNotation.bind<EitherTypeLambda>(map, flatMap)
879
-
880
- /**
881
- * The "do simulation" in Effect 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`.
882
- *
883
- * Here's how the do simulation works:
884
- *
885
- * 1. Start the do simulation using the `Do` value
886
- * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values
887
- * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
888
- * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
889
- *
890
- * @example
891
- * ```ts
892
- * import * as assert from "node:assert"
893
- * import { Either, pipe } from "effect"
894
- *
895
- * const result = pipe(
896
- * Either.Do,
897
- * Either.bind("x", () => Either.right(2)),
898
- * Either.bind("y", () => Either.right(3)),
899
- * Either.let("sum", ({ x, y }) => x + y)
900
- * )
901
- * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))
902
- * ```
903
- *
904
- * @see {@link Do}
905
- * @see {@link bind}
906
- * @see {@link let_ let}
907
- *
908
- * @category do notation
909
- * @since 2.0.0
910
- */
911
- export const bindTo: {
912
- <N extends string>(name: N): <A, E>(self: Either<A, E>) => Either<{ [K in N]: A }, E>
913
- <A, E, N extends string>(self: Either<A, E>, name: N): Either<{ [K in N]: A }, E>
914
- } = doNotation.bindTo<EitherTypeLambda>(map)
915
-
916
- const let_: {
917
- <N extends string, A extends object, B>(
918
- name: Exclude<N, keyof A>,
919
- f: (r: NoInfer<A>) => B
920
- ): <E>(self: Either<A, E>) => Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, E>
921
- <A extends object, E, N extends string, B>(
922
- self: Either<A, E>,
923
- name: Exclude<N, keyof A>,
924
- f: (r: NoInfer<A>) => B
925
- ): Either<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, E>
926
- } = doNotation.let_<EitherTypeLambda>(map)
927
-
928
- export {
929
- /**
930
- * The "do simulation" in Effect 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`.
931
- *
932
- * Here's how the do simulation works:
933
- *
934
- * 1. Start the do simulation using the `Do` value
935
- * 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Either` values
936
- * 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
937
- * 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
938
- *
939
- * @example
940
- * ```ts
941
- * import * as assert from "node:assert"
942
- * import { Either, pipe } from "effect"
943
- *
944
- * const result = pipe(
945
- * Either.Do,
946
- * Either.bind("x", () => Either.right(2)),
947
- * Either.bind("y", () => Either.right(3)),
948
- * Either.let("sum", ({ x, y }) => x + y)
949
- * )
950
- * assert.deepStrictEqual(result, Either.right({ x: 2, y: 3, sum: 5 }))
951
- * ```
952
- *
953
- * @see {@link Do}
954
- * @see {@link bindTo}
955
- * @see {@link bind}
956
- *
957
- * @category do notation
958
- * @since 2.0.0
959
- */
960
- let_ as let
961
- }
962
-
963
- /**
964
- * Converts an `Option` of an `Either` into an `Either` of an `Option`.
965
- *
966
- * **Details**
967
- *
968
- * This function transforms an `Option<Either<A, E>>` into an
969
- * `Either<Option<A>, E>`. If the `Option` is `None`, the resulting `Either`
970
- * will be a `Right` with a `None` value. If the `Option` is `Some`, the
971
- * inner `Either` will be executed, and its result wrapped in a `Some`.
972
- *
973
- * @example
974
- * ```ts
975
- * import { Effect, Either, Option } from "effect"
976
- *
977
- * // ┌─── Option<Either<number, never>>
978
- * // ▼
979
- * const maybe = Option.some(Either.right(42))
980
- *
981
- * // ┌─── Either<Option<number>, never, never>
982
- * // ▼
983
- * const result = Either.transposeOption(maybe)
984
- *
985
- * console.log(Effect.runSync(result))
986
- * // Output: { _id: 'Option', _tag: 'Some', value: 42 }
987
- * ```
988
- *
989
- * @since 3.14.0
990
- * @category Optional Wrapping & Unwrapping
991
- */
992
- export const transposeOption = <A = never, E = never>(
993
- self: Option<Either<A, E>>
994
- ): Either<Option<A>, E> => {
995
- return option_.isNone(self) ? right(option_.none) : map(self.value, option_.some)
996
- }
997
-
998
- /**
999
- * Applies an `Either` on an `Option` and transposes the result.
1000
- *
1001
- * **Details**
1002
- *
1003
- * If the `Option` is `None`, the resulting `Either` will immediately succeed with a `Right` value of `None`.
1004
- * If the `Option` is `Some`, the transformation function will be applied to the inner value, and its result wrapped in a `Some`.
1005
- *
1006
- * @example
1007
- * ```ts
1008
- * import { Either, Option, pipe } from "effect"
1009
- *
1010
- * // ┌─── Either<Option<number>, never>>
1011
- * // ▼
1012
- * const noneResult = pipe(
1013
- * Option.none(),
1014
- * Either.transposeMapOption(() => Either.right(42)) // will not be executed
1015
- * )
1016
- * console.log(noneResult)
1017
- * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'None' } }
1018
- *
1019
- * // ┌─── Either<Option<number>, never>>
1020
- * // ▼
1021
- * const someRightResult = pipe(
1022
- * Option.some(42),
1023
- * Either.transposeMapOption((value) => Either.right(value * 2))
1024
- * )
1025
- * console.log(someRightResult)
1026
- * // Output: { _id: 'Either', _tag: 'Right', right: { _id: 'Option', _tag: 'Some', value: 84 } }
1027
- * ```
1028
- *
1029
- * @since 3.15.0
1030
- * @category Optional Wrapping & Unwrapping
1031
- */
1032
- export const transposeMapOption = dual<
1033
- <A, B, E = never>(
1034
- f: (self: A) => Either<B, E>
1035
- ) => (self: Option<A>) => Either<Option<B>, E>,
1036
- <A, B, E = never>(
1037
- self: Option<A>,
1038
- f: (self: A) => Either<B, E>
1039
- ) => Either<Option<B>, E>
1040
- >(2, (self, f) => option_.isNone(self) ? right(option_.none) : map(f(self.value), option_.some))