@clayroach/effect 3.19.14-source-capture.7 → 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/Predicate.ts DELETED
@@ -1,1405 +0,0 @@
1
- /**
2
- * This module provides a collection of functions for working with predicates and refinements.
3
- *
4
- * A `Predicate<A>` is a function that takes a value of type `A` and returns a boolean.
5
- * It is used to check if a value satisfies a certain condition.
6
- *
7
- * A `Refinement<A, B>` is a special type of predicate that not only checks a condition
8
- * but also provides a type guard, allowing TypeScript to narrow the type of the input
9
- * value from `A` to a more specific type `B` within a conditional block.
10
- *
11
- * The module includes:
12
- * - Basic predicates and refinements for common types (e.g., `isString`, `isNumber`).
13
- * - Combinators to create new predicates from existing ones (e.g., `and`, `or`, `not`).
14
- * - Advanced combinators for working with data structures (e.g., `tuple`, `struct`).
15
- * - Type-level utilities for inspecting predicate and refinement types.
16
- *
17
- * @since 2.0.0
18
- */
19
- import { dual, isFunction as isFunction_ } from "./Function.js"
20
- import type { TypeLambda } from "./HKT.js"
21
- import type { TupleOf, TupleOfAtLeast } from "./Types.js"
22
-
23
- /**
24
- * Represents a function that takes a value of type `A` and returns `true` if the value
25
- * satisfies some condition, `false` otherwise.
26
- *
27
- * @example
28
- * ```ts
29
- * import { Predicate } from "effect"
30
- * import * as assert from "node:assert"
31
- *
32
- * const isEven: Predicate.Predicate<number> = (n) => n % 2 === 0
33
- *
34
- * assert.strictEqual(isEven(2), true)
35
- * assert.strictEqual(isEven(3), false)
36
- * ```
37
- *
38
- * @category models
39
- * @since 2.0.0
40
- */
41
- export interface Predicate<in A> {
42
- (a: A): boolean
43
- }
44
-
45
- /**
46
- * A `TypeLambda` for `Predicate`. This is used to support higher-kinded types
47
- * and allows `Predicate` to be used in generic contexts within the `effect` ecosystem.
48
- *
49
- * @category type lambdas
50
- * @since 2.0.0
51
- */
52
- export interface PredicateTypeLambda extends TypeLambda {
53
- readonly type: Predicate<this["Target"]>
54
- }
55
-
56
- /**
57
- * Represents a function that serves as a type guard.
58
- *
59
- * A `Refinement<A, B>` is a function that takes a value of type `A` and returns a
60
- * type predicate `a is B`, where `B` is a subtype of `A`. If the function returns
61
- * `true`, TypeScript will narrow the type of the input variable to `B`.
62
- *
63
- * @example
64
- * ```ts
65
- * import { Predicate } from "effect"
66
- * import * as assert from "node:assert"
67
- *
68
- * const isString: Predicate.Refinement<unknown, string> = (u): u is string => typeof u === "string"
69
- *
70
- * const value: unknown = "hello"
71
- *
72
- * if (isString(value)) {
73
- * // value is now known to be a string
74
- * assert.strictEqual(value.toUpperCase(), "HELLO")
75
- * }
76
- * ```
77
- *
78
- * @category models
79
- * @since 2.0.0
80
- */
81
- export interface Refinement<in A, out B extends A> {
82
- (a: A): a is B
83
- }
84
-
85
- /**
86
- * A namespace for type-level utilities for `Predicate`.
87
- *
88
- * @since 3.6.0
89
- * @category type-level
90
- */
91
- export declare namespace Predicate {
92
- /**
93
- * Extracts the input type `A` from a `Predicate<A>`.
94
- *
95
- * @example
96
- * ```ts
97
- * import { type Predicate } from "effect"
98
- *
99
- * type T = Predicate.Predicate.In<Predicate.Predicate<string>> // T is string
100
- * ```
101
- *
102
- * @since 3.6.0
103
- * @category type-level
104
- */
105
- export type In<T extends Any> = [T] extends [Predicate<infer _A>] ? _A : never
106
- /**
107
- * A type representing any `Predicate`.
108
- *
109
- * @since 3.6.0
110
- * @category type-level
111
- */
112
- export type Any = Predicate<never>
113
- }
114
-
115
- /**
116
- * A namespace for type-level utilities for `Refinement`.
117
- *
118
- * @since 3.6.0
119
- * @category type-level
120
- */
121
- export declare namespace Refinement {
122
- /**
123
- * Extracts the input type `A` from a `Refinement<A, B>`.
124
- *
125
- * @example
126
- * ```ts
127
- * import { type Predicate } from "effect"
128
- *
129
- * type IsString = Predicate.Refinement<unknown, string>
130
- * type T = Predicate.Refinement.In<IsString> // T is unknown
131
- * ```
132
- *
133
- * @since 3.6.0
134
- * @category type-level
135
- */
136
- export type In<T extends Any> = [T] extends [Refinement<infer _A, infer _>] ? _A : never
137
- /**
138
- * Extracts the output (refined) type `B` from a `Refinement<A, B>`.
139
- *
140
- * @example
141
- * ```ts
142
- * import { type Predicate } from "effect"
143
- *
144
- * type IsString = Predicate.Refinement<unknown, string>
145
- * type T = Predicate.Refinement.Out<IsString> // T is string
146
- * ```
147
- *
148
- * @since 3.6.0
149
- * @category type-level
150
- */
151
- export type Out<T extends Any> = [T] extends [Refinement<infer _, infer _B>] ? _B : never
152
- /**
153
- * A type representing any `Refinement`.
154
- *
155
- * @since 3.6.0
156
- * @category type-level
157
- */
158
- export type Any = Refinement<any, any>
159
- }
160
-
161
- /**
162
- * Transforms a `Predicate<A>` into a `Predicate<B>` by applying a function `(b: B) => A`
163
- * to the input before passing it to the predicate. This is also known as "contramap" or
164
- * "pre-composition".
165
- *
166
- * @example
167
- * ```ts
168
- * import { Predicate, Number } from "effect"
169
- * import * as assert from "node:assert"
170
- *
171
- * // A predicate on numbers
172
- * const isPositive: Predicate.Predicate<number> = Number.greaterThan(0)
173
- *
174
- * // A function from `string` to `number`
175
- * const stringLength = (s: string): number => s.length
176
- *
177
- * // Create a new predicate on strings by mapping the input
178
- * const hasPositiveLength = Predicate.mapInput(isPositive, stringLength)
179
- *
180
- * assert.strictEqual(hasPositiveLength("hello"), true)
181
- * assert.strictEqual(hasPositiveLength(""), false)
182
- * ```
183
- *
184
- * @category combinators
185
- * @since 2.0.0
186
- */
187
- export const mapInput: {
188
- <B, A>(f: (b: B) => A): (self: Predicate<A>) => Predicate<B>
189
- <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B>
190
- } = dual(2, <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B> => (b) => self(f(b)))
191
-
192
- /**
193
- * A refinement that checks if a `ReadonlyArray<T>` is a tuple with exactly `N` elements.
194
- * If the check is successful, the type is narrowed to `TupleOf<N, T>`.
195
- *
196
- * @example
197
- * ```ts
198
- * import * as assert from "node:assert"
199
- * import { isTupleOf } from "effect/Predicate"
200
- *
201
- * const isTupleOf3 = isTupleOf(3)
202
- *
203
- * assert.strictEqual(isTupleOf3([1, 2, 3]), true);
204
- * assert.strictEqual(isTupleOf3([1, 2]), false);
205
- *
206
- * const arr: number[] = [1, 2, 3];
207
- * if (isTupleOf(arr, 3)) {
208
- * // The type of arr is now [number, number, number]
209
- * const [a, b, c] = arr;
210
- * assert.deepStrictEqual([a, b, c], [1, 2, 3])
211
- * }
212
- * ```
213
- *
214
- * @category guards
215
- * @since 3.3.0
216
- */
217
- export const isTupleOf: {
218
- <N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOf<N, T>
219
- <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>
220
- } = dual(2, <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T> => self.length === n)
221
-
222
- /**
223
- * A refinement that checks if a `ReadonlyArray<T>` is a tuple with at least `N` elements.
224
- * If the check is successful, the type is narrowed to `TupleOfAtLeast<N, T>`.
225
- *
226
- * @example
227
- * ```ts
228
- * import * as assert from "node:assert"
229
- * import { isTupleOfAtLeast } from "effect/Predicate"
230
- *
231
- * const isTupleOfAtLeast3 = isTupleOfAtLeast(3)
232
- *
233
- * assert.strictEqual(isTupleOfAtLeast3([1, 2, 3]), true);
234
- * assert.strictEqual(isTupleOfAtLeast3([1, 2, 3, 4]), true);
235
- * assert.strictEqual(isTupleOfAtLeast3([1, 2]), false);
236
- *
237
- * const arr: number[] = [1, 2, 3, 4];
238
- * if (isTupleOfAtLeast(arr, 3)) {
239
- * // The type of arr is now [number, number, number, ...number[]]
240
- * const [a, b, c] = arr;
241
- * assert.deepStrictEqual([a, b, c], [1, 2, 3])
242
- * }
243
- * ```
244
- *
245
- * @category guards
246
- * @since 3.3.0
247
- */
248
- export const isTupleOfAtLeast: {
249
- <N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOfAtLeast<N, T>
250
- <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T>
251
- } = dual(2, <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T> => self.length >= n)
252
-
253
- /**
254
- * A predicate that checks if a value is "truthy" in JavaScript.
255
- * Fails for `false`, `0`, `-0`, `0n`, `""`, `null`, `undefined`, and `NaN`.
256
- *
257
- * @example
258
- * ```ts
259
- * import * as assert from "node:assert"
260
- * import { isTruthy } from "effect/Predicate"
261
- *
262
- * assert.strictEqual(isTruthy(1), true)
263
- * assert.strictEqual(isTruthy("hello"), true)
264
- * assert.strictEqual(isTruthy({}), true)
265
- *
266
- * assert.strictEqual(isTruthy(0), false)
267
- * assert.strictEqual(isTruthy(""), false)
268
- * assert.strictEqual(isTruthy(null), false)
269
- * assert.strictEqual(isTruthy(undefined), false)
270
- * ```
271
- *
272
- * @category guards
273
- * @since 2.0.0
274
- */
275
- export const isTruthy = (input: unknown) => !!input
276
-
277
- /**
278
- * A refinement that checks if a value is a `Set`.
279
- *
280
- * @example
281
- * ```ts
282
- * import * as assert from "node:assert"
283
- * import { isSet } from "effect/Predicate"
284
- *
285
- * assert.strictEqual(isSet(new Set([1, 2])), true)
286
- * assert.strictEqual(isSet(new Set()), true)
287
- *
288
- * assert.strictEqual(isSet({}), false)
289
- * assert.strictEqual(isSet([1, 2]), false)
290
- * ```
291
- *
292
- * @category guards
293
- * @since 2.0.0
294
- */
295
- export const isSet = (input: unknown): input is Set<unknown> => input instanceof Set
296
-
297
- /**
298
- * A refinement that checks if a value is a `Map`.
299
- *
300
- * @example
301
- * ```ts
302
- * import * as assert from "node:assert"
303
- * import { isMap } from "effect/Predicate"
304
- *
305
- * assert.strictEqual(isMap(new Map()), true)
306
- *
307
- * assert.strictEqual(isMap({}), false)
308
- * assert.strictEqual(isMap(new Set()), false)
309
- * ```
310
- *
311
- * @category guards
312
- * @since 2.0.0
313
- */
314
- export const isMap = (input: unknown): input is Map<unknown, unknown> => input instanceof Map
315
-
316
- /**
317
- * A refinement that checks if a value is a `string`.
318
- *
319
- * @example
320
- * ```ts
321
- * import * as assert from "node:assert"
322
- * import { isString } from "effect/Predicate"
323
- *
324
- * assert.strictEqual(isString("hello"), true)
325
- * assert.strictEqual(isString(""), true)
326
- *
327
- * assert.strictEqual(isString(123), false)
328
- * assert.strictEqual(isString(null), false)
329
- * ```
330
- *
331
- * @category guards
332
- * @since 2.0.0
333
- */
334
- export const isString = (input: unknown): input is string => typeof input === "string"
335
-
336
- /**
337
- * A refinement that checks if a value is a `number`.
338
- *
339
- * @example
340
- * ```ts
341
- * import * as assert from "node:assert"
342
- * import { isNumber } from "effect/Predicate"
343
- *
344
- * assert.strictEqual(isNumber(123), true)
345
- * assert.strictEqual(isNumber(0), true)
346
- * assert.strictEqual(isNumber(-1.5), true)
347
- * assert.strictEqual(isNumber(NaN), true)
348
- *
349
- * assert.strictEqual(isNumber("123"), false)
350
- * ```
351
- *
352
- * @category guards
353
- * @since 2.0.0
354
- */
355
- export const isNumber = (input: unknown): input is number => typeof input === "number"
356
-
357
- /**
358
- * A refinement that checks if a value is a `boolean`.
359
- *
360
- * @example
361
- * ```ts
362
- * import * as assert from "node:assert"
363
- * import { isBoolean } from "effect/Predicate"
364
- *
365
- * assert.strictEqual(isBoolean(true), true)
366
- * assert.strictEqual(isBoolean(false), true)
367
- *
368
- * assert.strictEqual(isBoolean("true"), false)
369
- * assert.strictEqual(isBoolean(0), false)
370
- * ```
371
- *
372
- * @category guards
373
- * @since 2.0.0
374
- */
375
- export const isBoolean = (input: unknown): input is boolean => typeof input === "boolean"
376
-
377
- /**
378
- * A refinement that checks if a value is a `bigint`.
379
- *
380
- * @example
381
- * ```ts
382
- * import * as assert from "node:assert"
383
- * import { isBigInt } from "effect/Predicate"
384
- *
385
- * assert.strictEqual(isBigInt(1n), true)
386
- *
387
- * assert.strictEqual(isBigInt(1), false)
388
- * assert.strictEqual(isBigInt("1"), false)
389
- * ```
390
- *
391
- * @category guards
392
- * @since 2.0.0
393
- */
394
- export const isBigInt = (input: unknown): input is bigint => typeof input === "bigint"
395
-
396
- /**
397
- * A refinement that checks if a value is a `symbol`.
398
- *
399
- * @example
400
- * ```ts
401
- * import * as assert from "node:assert"
402
- * import { isSymbol } from "effect/Predicate"
403
- *
404
- * assert.strictEqual(isSymbol(Symbol.for("a")), true)
405
- *
406
- * assert.strictEqual(isSymbol("a"), false)
407
- * ```
408
- *
409
- * @category guards
410
- * @since 2.0.0
411
- */
412
- export const isSymbol = (input: unknown): input is symbol => typeof input === "symbol"
413
-
414
- // TODO: make public
415
- /**
416
- * A refinement that checks if a value is a valid `PropertyKey` (a `string`, `number`, or `symbol`).
417
- * @internal
418
- */
419
- export const isPropertyKey = (u: unknown): u is PropertyKey => isString(u) || isNumber(u) || isSymbol(u)
420
-
421
- /**
422
- * A refinement that checks if a value is a `Function`.
423
- *
424
- * @example
425
- * ```ts
426
- * import * as assert from "node:assert"
427
- * import { isFunction } from "effect/Predicate"
428
- *
429
- * assert.strictEqual(isFunction(() => {}), true)
430
- * assert.strictEqual(isFunction(isFunction), true)
431
- *
432
- * assert.strictEqual(isFunction("function"), false)
433
- * ```
434
- *
435
- * @category guards
436
- * @since 2.0.0
437
- */
438
- export const isFunction: (input: unknown) => input is Function = isFunction_
439
-
440
- /**
441
- * A refinement that checks if a value is `undefined`.
442
- *
443
- * @example
444
- * ```ts
445
- * import * as assert from "node:assert"
446
- * import { isUndefined } from "effect/Predicate"
447
- *
448
- * assert.strictEqual(isUndefined(undefined), true)
449
- *
450
- * assert.strictEqual(isUndefined(null), false)
451
- * assert.strictEqual(isUndefined("undefined"), false)
452
- * ```
453
- *
454
- * @category guards
455
- * @since 2.0.0
456
- */
457
- export const isUndefined = (input: unknown): input is undefined => input === undefined
458
-
459
- /**
460
- * A refinement that checks if a value is not `undefined`.
461
- *
462
- * @example
463
- * ```ts
464
- * import * as assert from "node:assert"
465
- * import { isNotUndefined } from "effect/Predicate"
466
- *
467
- * assert.strictEqual(isNotUndefined(null), true)
468
- * assert.strictEqual(isNotUndefined("value"), true)
469
- *
470
- * assert.strictEqual(isNotUndefined(undefined), false)
471
- * ```
472
- *
473
- * @category guards
474
- * @since 2.0.0
475
- */
476
- export const isNotUndefined = <A>(input: A): input is Exclude<A, undefined> => input !== undefined
477
-
478
- /**
479
- * A refinement that checks if a value is `null`.
480
- *
481
- * @example
482
- * ```ts
483
- * import * as assert from "node:assert"
484
- * import { isNull } from "effect/Predicate"
485
- *
486
- * assert.strictEqual(isNull(null), true)
487
- *
488
- * assert.strictEqual(isNull(undefined), false)
489
- * assert.strictEqual(isNull("null"), false)
490
- * ```
491
- *
492
- * @category guards
493
- * @since 2.0.0
494
- */
495
- export const isNull = (input: unknown): input is null => input === null
496
-
497
- /**
498
- * A refinement that checks if a value is not `null`.
499
- *
500
- * @example
501
- * ```ts
502
- * import * as assert from "node:assert"
503
- * import { isNotNull } from "effect/Predicate"
504
- *
505
- * assert.strictEqual(isNotNull(undefined), true)
506
- * assert.strictEqual(isNotNull("value"), true)
507
- *
508
- * assert.strictEqual(isNotNull(null), false)
509
- * ```
510
- *
511
- * @category guards
512
- * @since 2.0.0
513
- */
514
- export const isNotNull = <A>(input: A): input is Exclude<A, null> => input !== null
515
-
516
- /**
517
- * A refinement that always returns `false`. The type is narrowed to `never`.
518
- *
519
- * @example
520
- * ```ts
521
- * import * as assert from "node:assert"
522
- * import { isNever } from "effect/Predicate"
523
- *
524
- * assert.strictEqual(isNever(1), false)
525
- * assert.strictEqual(isNever(null), false)
526
- * assert.strictEqual(isNever({}), false)
527
- * ```
528
- *
529
- * @category guards
530
- * @since 2.0.0
531
- */
532
- export const isNever: (input: unknown) => input is never = (_: unknown): _ is never => false
533
-
534
- /**
535
- * A refinement that always returns `true`. The type is narrowed to `unknown`.
536
- *
537
- * @example
538
- * ```ts
539
- * import * as assert from "node:assert"
540
- * import { isUnknown } from "effect/Predicate"
541
- *
542
- * assert.strictEqual(isUnknown(1), true)
543
- * assert.strictEqual(isUnknown(null), true)
544
- * assert.strictEqual(isUnknown({}), true)
545
- * ```
546
- *
547
- * @category guards
548
- * @since 2.0.0
549
- */
550
- export const isUnknown: (input: unknown) => input is unknown = (_): _ is unknown => true
551
-
552
- /**
553
- * Checks if the input is an object or an array.
554
- * @internal
555
- */
556
- export const isRecordOrArray = (input: unknown): input is { [x: PropertyKey]: unknown } =>
557
- typeof input === "object" && input !== null
558
-
559
- /**
560
- * A refinement that checks if a value is an `object`. Note that in JavaScript,
561
- * arrays and functions are also considered objects.
562
- *
563
- * @example
564
- * ```ts
565
- * import * as assert from "node:assert"
566
- * import { isObject } from "effect/Predicate"
567
- *
568
- * assert.strictEqual(isObject({}), true)
569
- * assert.strictEqual(isObject([]), true)
570
- * assert.strictEqual(isObject(() => {}), true)
571
- *
572
- * assert.strictEqual(isObject(null), false)
573
- * assert.strictEqual(isObject("hello"), false)
574
- * ```
575
- *
576
- * @category guards
577
- * @since 2.0.0
578
- * @see isRecord to check for plain objects (excluding arrays and functions).
579
- */
580
- export const isObject = (input: unknown): input is object => isRecordOrArray(input) || isFunction(input)
581
-
582
- /**
583
- * A refinement that checks if a value is an object-like value and has a specific property key.
584
- *
585
- * @example
586
- * ```ts
587
- * import * as assert from "node:assert"
588
- * import { hasProperty } from "effect/Predicate"
589
- *
590
- * assert.strictEqual(hasProperty({ a: 1 }, "a"), true)
591
- * assert.strictEqual(hasProperty({ a: 1 }, "b"), false)
592
- *
593
- * const value: unknown = { name: "Alice" };
594
- * if (hasProperty(value, "name")) {
595
- * // The type of `value` is narrowed to `{ name: unknown }`
596
- * // and we can safely access `value.name`
597
- * console.log(value.name)
598
- * }
599
- * ```
600
- *
601
- * @category guards
602
- * @since 2.0.0
603
- */
604
- export const hasProperty: {
605
- <P extends PropertyKey>(property: P): (self: unknown) => self is { [K in P]: unknown }
606
- <P extends PropertyKey>(self: unknown, property: P): self is { [K in P]: unknown }
607
- } = dual(
608
- 2,
609
- <P extends PropertyKey>(self: unknown, property: P): self is { [K in P]: unknown } =>
610
- isObject(self) && (property in self)
611
- )
612
-
613
- /**
614
- * A refinement that checks if a value is an object with a `_tag` property
615
- * that matches the given tag. This is a powerful tool for working with
616
- * discriminated union types.
617
- *
618
- * @example
619
- * ```ts
620
- * import * as assert from "node:assert"
621
- * import { isTagged } from "effect/Predicate"
622
- *
623
- * type Shape = { _tag: "circle"; radius: number } | { _tag: "square"; side: number }
624
- *
625
- * const isCircle = isTagged("circle")
626
- *
627
- * const shape1: Shape = { _tag: "circle", radius: 10 }
628
- * const shape2: Shape = { _tag: "square", side: 5 }
629
- *
630
- * assert.strictEqual(isCircle(shape1), true)
631
- * assert.strictEqual(isCircle(shape2), false)
632
- *
633
- * if (isCircle(shape1)) {
634
- * // shape1 is now narrowed to { _tag: "circle"; radius: number }
635
- * assert.strictEqual(shape1.radius, 10)
636
- * }
637
- * ```
638
- *
639
- * @category guards
640
- * @since 2.0.0
641
- */
642
- export const isTagged: {
643
- <K extends string>(tag: K): (self: unknown) => self is { _tag: K }
644
- <K extends string>(self: unknown, tag: K): self is { _tag: K }
645
- } = dual(
646
- 2,
647
- <K extends string>(self: unknown, tag: K): self is { _tag: K } => hasProperty(self, "_tag") && self["_tag"] === tag
648
- )
649
-
650
- /**
651
- * A refinement that checks if a value is either `null` or `undefined`.
652
- *
653
- * @example
654
- * ```ts
655
- * import * as assert from "node:assert"
656
- * import { isNullable } from "effect/Predicate"
657
- *
658
- * assert.strictEqual(isNullable(null), true)
659
- * assert.strictEqual(isNullable(undefined), true)
660
- *
661
- * assert.strictEqual(isNullable(0), false)
662
- * assert.strictEqual(isNullable(""), false)
663
- * ```
664
- *
665
- * @category guards
666
- * @since 2.0.0
667
- * @see isNotNullable
668
- */
669
- export const isNullable = <A>(input: A): input is Extract<A, null | undefined> => input === null || input === undefined
670
-
671
- /**
672
- * A refinement that checks if a value is neither `null` nor `undefined`.
673
- * The type is narrowed to `NonNullable<A>`.
674
- *
675
- * @example
676
- * ```ts
677
- * import * as assert from "node:assert"
678
- * import { isNotNullable } from "effect/Predicate"
679
- *
680
- * assert.strictEqual(isNotNullable(0), true)
681
- * assert.strictEqual(isNotNullable("hello"), true)
682
- *
683
- * assert.strictEqual(isNotNullable(null), false)
684
- * assert.strictEqual(isNotNullable(undefined), false)
685
- * ```
686
- *
687
- * @category guards
688
- * @since 2.0.0
689
- * @see isNullable
690
- */
691
- export const isNotNullable = <A>(input: A): input is NonNullable<A> => input !== null && input !== undefined
692
-
693
- /**
694
- * A refinement that checks if a value is an instance of `Error`.
695
- *
696
- * @example
697
- * ```ts
698
- * import * as assert from "node:assert"
699
- * import { isError } from "effect/Predicate"
700
- *
701
- * assert.strictEqual(isError(new Error("boom")), true)
702
- * assert.strictEqual(isError(new TypeError("boom")), true)
703
- *
704
- * assert.strictEqual(isError({ message: "boom" }), false)
705
- * assert.strictEqual(isError("boom"), false)
706
- * ```
707
- *
708
- * @category guards
709
- * @since 2.0.0
710
- */
711
- export const isError = (input: unknown): input is Error => input instanceof Error
712
-
713
- /**
714
- * A refinement that checks if a value is a `Uint8Array`.
715
- *
716
- * @example
717
- * ```ts
718
- * import * as assert from "node:assert"
719
- * import { isUint8Array } from "effect/Predicate"
720
- *
721
- * assert.strictEqual(isUint8Array(new Uint8Array()), true)
722
- *
723
- * assert.strictEqual(isUint8Array(new Uint16Array()), false)
724
- * assert.strictEqual(isUint8Array([1, 2, 3]), false)
725
- * ```
726
- *
727
- * @category guards
728
- * @since 2.0.0
729
- */
730
- export const isUint8Array = (input: unknown): input is Uint8Array => input instanceof Uint8Array
731
-
732
- /**
733
- * A refinement that checks if a value is a `Date` object.
734
- *
735
- * @example
736
- * ```ts
737
- * import * as assert from "node:assert"
738
- * import { isDate } from "effect/Predicate"
739
- *
740
- * assert.strictEqual(isDate(new Date()), true)
741
- *
742
- * assert.strictEqual(isDate(Date.now()), false) // `Date.now()` returns a number
743
- * assert.strictEqual(isDate("2023-01-01"), false)
744
- * ```
745
- *
746
- * @category guards
747
- * @since 2.0.0
748
- */
749
- export const isDate = (input: unknown): input is Date => input instanceof Date
750
-
751
- /**
752
- * A refinement that checks if a value is an `Iterable`.
753
- * Many built-in types are iterable, such as `Array`, `string`, `Map`, and `Set`.
754
- *
755
- * @example
756
- * ```ts
757
- * import * as assert from "node:assert"
758
- * import { isIterable } from "effect/Predicate"
759
- *
760
- * assert.strictEqual(isIterable([]), true)
761
- * assert.strictEqual(isIterable("hello"), true)
762
- * assert.strictEqual(isIterable(new Set()), true)
763
- *
764
- * assert.strictEqual(isIterable({}), false)
765
- * assert.strictEqual(isIterable(123), false)
766
- * ```
767
- *
768
- * @category guards
769
- * @since 2.0.0
770
- */
771
- export const isIterable = (input: unknown): input is Iterable<unknown> =>
772
- typeof input === "string" || hasProperty(input, Symbol.iterator)
773
-
774
- /**
775
- * A refinement that checks if a value is a record (i.e., a plain object).
776
- * This check returns `false` for arrays, `null`, and functions.
777
- *
778
- * @example
779
- * ```ts
780
- * import * as assert from "node:assert"
781
- * import { isRecord } from "effect/Predicate"
782
- *
783
- * assert.strictEqual(isRecord({}), true)
784
- * assert.strictEqual(isRecord({ a: 1 }), true)
785
- *
786
- * assert.strictEqual(isRecord([]), false)
787
- * assert.strictEqual(isRecord(new Date()), false)
788
- * assert.strictEqual(isRecord(null), false)
789
- * assert.strictEqual(isRecord(() => null), false)
790
- * ```
791
- *
792
- * @category guards
793
- * @since 2.0.0
794
- * @see isObject
795
- */
796
- export const isRecord = (input: unknown): input is { [x: string | symbol]: unknown } =>
797
- isRecordOrArray(input) && !Array.isArray(input)
798
-
799
- /**
800
- * A refinement that checks if a value is a readonly record (i.e., a plain object).
801
- * This check returns `false` for arrays, `null`, and functions.
802
- *
803
- * This is an alias for `isRecord`.
804
- *
805
- * @example
806
- * ```ts
807
- * import * as assert from "node:assert"
808
- * import { isReadonlyRecord } from "effect/Predicate"
809
- *
810
- * assert.strictEqual(isReadonlyRecord({}), true)
811
- * assert.strictEqual(isReadonlyRecord({ a: 1 }), true)
812
- *
813
- * assert.strictEqual(isReadonlyRecord([]), false)
814
- * assert.strictEqual(isReadonlyRecord(null), false)
815
- * ```
816
- *
817
- * @category guards
818
- * @since 2.0.0
819
- */
820
- export const isReadonlyRecord: (
821
- input: unknown
822
- ) => input is { readonly [x: string | symbol]: unknown } = isRecord
823
-
824
- /**
825
- * A refinement that checks if a value is a `Promise`. It performs a duck-typing check
826
- * for `.then` and `.catch` methods.
827
- *
828
- * @example
829
- * ```ts
830
- * import * as assert from "node:assert"
831
- * import { isPromise } from "effect/Predicate"
832
- *
833
- * assert.strictEqual(isPromise(Promise.resolve(1)), true)
834
- * assert.strictEqual(isPromise(new Promise(() => {})), true)
835
- *
836
- * assert.strictEqual(isPromise({ then() {} }), false) // Missing .catch
837
- * assert.strictEqual(isPromise({}), false)
838
- * ```
839
- *
840
- * @category guards
841
- * @since 2.0.0
842
- * @see isPromiseLike
843
- */
844
- export const isPromise = (
845
- input: unknown
846
- ): input is Promise<unknown> =>
847
- hasProperty(input, "then") && "catch" in input && isFunction(input.then) && isFunction(input.catch)
848
-
849
- /**
850
- * A refinement that checks if a value is `PromiseLike`. It performs a duck-typing
851
- * check for a `.then` method.
852
- *
853
- * @example
854
- * ```ts
855
- * import * as assert from "node:assert"
856
- * import { isPromiseLike } from "effect/Predicate"
857
- *
858
- * assert.strictEqual(isPromiseLike(Promise.resolve(1)), true)
859
- * assert.strictEqual(isPromiseLike({ then: () => {} }), true)
860
- *
861
- * assert.strictEqual(isPromiseLike({}), false)
862
- * ```
863
- *
864
- * @category guards
865
- * @since 2.0.0
866
- * @see isPromise
867
- */
868
- export const isPromiseLike = (
869
- input: unknown
870
- ): input is PromiseLike<unknown> => hasProperty(input, "then") && isFunction(input.then)
871
-
872
- /**
873
- * A refinement that checks if a value is a `RegExp`.
874
- *
875
- * @example
876
- * ```ts
877
- * import * as assert from "node:assert"
878
- * import { Predicate } from "effect"
879
- *
880
- * assert.strictEqual(Predicate.isRegExp(/a/), true)
881
- * assert.strictEqual(Predicate.isRegExp(new RegExp("a")), true)
882
- *
883
- * assert.strictEqual(Predicate.isRegExp("/a/"), false)
884
- * ```
885
- *
886
- * @category guards
887
- * @since 3.9.0
888
- */
889
- export const isRegExp = (input: unknown): input is RegExp => input instanceof RegExp
890
-
891
- /**
892
- * Composes a `Refinement` with another `Refinement` or `Predicate`.
893
- *
894
- * This can be used to chain checks. The first refinement is applied, and if it
895
- * passes, the second check is applied to the same value, potentially refining
896
- * the type further.
897
- *
898
- * @example
899
- * ```ts
900
- * import { Predicate } from "effect"
901
- * import * as assert from "node:assert"
902
- *
903
- * const isString = (u: unknown): u is string => typeof u === "string"
904
- * const minLength = (n: number) => (s: string): boolean => s.length >= n
905
- *
906
- * // Create a refinement that checks for a string with a minimum length of 3
907
- * const isLongString = Predicate.compose(isString, minLength(3))
908
- *
909
- * let value: unknown = "hello"
910
- *
911
- * assert.strictEqual(isLongString(value), true)
912
- * if (isLongString(value)) {
913
- * // value is narrowed to string
914
- * assert.strictEqual(value.toUpperCase(), "HELLO")
915
- * }
916
- * assert.strictEqual(isLongString("hi"), false)
917
- * ```
918
- *
919
- * @since 2.0.0
920
- */
921
- export const compose: {
922
- <A, B extends A, C extends B, D extends C>(bc: Refinement<C, D>): (ab: Refinement<A, B>) => Refinement<A, D>
923
- <A, B extends A>(bc: Predicate<NoInfer<B>>): (ab: Refinement<A, B>) => Refinement<A, B>
924
- <A, B extends A, C extends B, D extends C>(ab: Refinement<A, B>, bc: Refinement<C, D>): Refinement<A, D>
925
- <A, B extends A>(ab: Refinement<A, B>, bc: Predicate<NoInfer<B>>): Refinement<A, B>
926
- } = dual(
927
- 2,
928
- <A, B extends A, C extends B, D extends C>(ab: Refinement<A, B>, bc: Refinement<C, D>): Refinement<A, D> =>
929
- (a): a is D => ab(a) && bc(a as C)
930
- )
931
-
932
- /**
933
- * Combines two predicates to test a tuple of two values. The first predicate tests the
934
- * first element of the tuple, and the second predicate tests the second element.
935
- *
936
- * @category combining
937
- * @since 2.0.0
938
- */
939
- export const product =
940
- <A, B>(self: Predicate<A>, that: Predicate<B>): Predicate<readonly [A, B]> /* readonly because contravariant */ =>
941
- ([a, b]) => self(a) && that(b)
942
-
943
- /**
944
- * Takes an iterable of predicates and returns a new predicate that tests an array of values.
945
- * The new predicate returns `true` if each predicate at a given index is satisfied by the
946
- * value at the same index in the array. The check stops at the length of the shorter of
947
- * the two iterables (predicates or values).
948
- *
949
- * @category combining
950
- * @since 2.0.0
951
- * @see tuple for a more powerful, variadic version.
952
- */
953
- export const all = <A>(
954
- collection: Iterable<Predicate<A>>
955
- ): Predicate<ReadonlyArray<A>> => {
956
- return (as) => {
957
- let collectionIndex = 0
958
- for (const p of collection) {
959
- if (collectionIndex >= as.length) {
960
- break
961
- }
962
- if (p(as[collectionIndex]) === false) {
963
- return false
964
- }
965
- collectionIndex++
966
- }
967
- return true
968
- }
969
- }
970
-
971
- /**
972
- * Combines a predicate for a single value and an iterable of predicates for the rest of an array.
973
- * Useful for checking the head and tail of an array separately.
974
- *
975
- * @category combining
976
- * @since 2.0.0
977
- */
978
- export const productMany = <A>(
979
- self: Predicate<A>,
980
- collection: Iterable<Predicate<A>>
981
- ): Predicate<readonly [A, ...Array<A>]> /* readonly because contravariant */ => {
982
- const rest = all(collection)
983
- return ([head, ...tail]) => self(head) === false ? false : rest(tail)
984
- }
985
-
986
- /**
987
- * Combines an array of predicates into a single predicate that tests an array of values.
988
- * This function is highly type-aware and will produce a `Refinement` if any of the provided
989
- * predicates are `Refinement`s, allowing for powerful type-narrowing of tuples.
990
- *
991
- * - If all predicates are `Predicate<T>`, the result is `Predicate<[T, T, ...]>`.
992
- * - If any predicate is a `Refinement<A, B>`, the result is a `Refinement` that narrows
993
- * the input tuple type to a more specific tuple type.
994
- *
995
- * @example
996
- * ```ts
997
- * import * as assert from "node:assert"
998
- * import { Predicate } from "effect"
999
- *
1000
- * const isString = (u: unknown): u is string => typeof u === "string"
1001
- * const isNumber = (u: unknown): u is number => typeof u === "number"
1002
- *
1003
- * // Create a refinement for a [string, number] tuple
1004
- * const isStringNumberTuple = Predicate.tuple(isString, isNumber)
1005
- *
1006
- * const value: [unknown, unknown] = ["hello", 123]
1007
- * if (isStringNumberTuple(value)) {
1008
- * // value is narrowed to [string, number]
1009
- * const [s, n] = value
1010
- * assert.strictEqual(s.toUpperCase(), "HELLO")
1011
- * assert.strictEqual(n.toFixed(2), "123.00")
1012
- * }
1013
- * assert.strictEqual(isStringNumberTuple(["hello", "123"]), false)
1014
- * ```
1015
- *
1016
- * @since 2.0.0
1017
- */
1018
- export const tuple: {
1019
- <T extends ReadonlyArray<Predicate.Any>>(
1020
- ...elements: T
1021
- ): [Extract<T[number], Refinement.Any>] extends [never] ? Predicate<{ readonly [I in keyof T]: Predicate.In<T[I]> }>
1022
- : Refinement<
1023
- { readonly [I in keyof T]: T[I] extends Refinement.Any ? Refinement.In<T[I]> : Predicate.In<T[I]> },
1024
- { readonly [I in keyof T]: T[I] extends Refinement.Any ? Refinement.Out<T[I]> : Predicate.In<T[I]> }
1025
- >
1026
- } = (...elements: ReadonlyArray<Predicate.Any>) => all(elements) as any
1027
-
1028
- /**
1029
- * Combines a record of predicates into a single predicate that tests a record of values.
1030
- * This function is highly type-aware and will produce a `Refinement` if any of the provided
1031
- * predicates are `Refinement`s, allowing for powerful type-narrowing of structs.
1032
- *
1033
- * - If all predicates are `Predicate<T>`, the result is `Predicate<{ k: T, ... }>`.
1034
- * - If any predicate is a `Refinement<A, B>`, the result is a `Refinement` that narrows
1035
- * the input record type to a more specific record type.
1036
- *
1037
- * @example
1038
- * ```ts
1039
- * import * as assert from "node:assert"
1040
- * import { Predicate } from "effect"
1041
- *
1042
- * const isString = (u: unknown): u is string => typeof u === "string"
1043
- * const isNumber = (u: unknown): u is number => typeof u === "number"
1044
- *
1045
- * const personPredicate = Predicate.struct({
1046
- * name: isString,
1047
- * age: isNumber
1048
- * })
1049
- *
1050
- * const value: { name: unknown; age: unknown } = { name: "Alice", age: 30 }
1051
- * if (personPredicate(value)) {
1052
- * // value is narrowed to { name: string; age: number }
1053
- * assert.strictEqual(value.name.toUpperCase(), "ALICE")
1054
- * assert.strictEqual(value.age.toFixed(0), "30")
1055
- * }
1056
- * assert.strictEqual(personPredicate({ name: "Bob", age: "40" }), false)
1057
- * ```
1058
- *
1059
- * @since 2.0.0
1060
- */
1061
- export const struct: {
1062
- <R extends Record<string, Predicate.Any>>(
1063
- fields: R
1064
- ): [Extract<R[keyof R], Refinement.Any>] extends [never] ?
1065
- Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]> }> :
1066
- Refinement<
1067
- { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]> },
1068
- { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]> }
1069
- >
1070
- } = (<R extends Record<string, Predicate.Any>>(fields: R) => {
1071
- const keys = Object.keys(fields)
1072
- return (a: Record<string, unknown>) => {
1073
- for (const key of keys) {
1074
- if (!fields[key](a[key] as never)) {
1075
- return false
1076
- }
1077
- }
1078
- return true
1079
- }
1080
- }) as any
1081
-
1082
- /**
1083
- * Returns a new predicate that is the logical negation of the given predicate.
1084
- *
1085
- * **Note**: If the input is a `Refinement`, the resulting predicate will be a
1086
- * simple `Predicate`, as TypeScript cannot infer the negative type.
1087
- *
1088
- * @example
1089
- * ```ts
1090
- * import * as assert from "node:assert"
1091
- * import { Predicate, Number } from "effect"
1092
- *
1093
- * const isNonPositive = Predicate.not(Number.greaterThan(0))
1094
- *
1095
- * assert.strictEqual(isNonPositive(-1), true)
1096
- * assert.strictEqual(isNonPositive(0), true)
1097
- * assert.strictEqual(isNonPositive(1), false)
1098
- * ```
1099
- *
1100
- * @category combinators
1101
- * @since 2.0.0
1102
- */
1103
- export const not = <A>(self: Predicate<A>): Predicate<A> => (a) => !self(a)
1104
-
1105
- /**
1106
- * Combines two predicates with a logical "OR". The resulting predicate returns `true`
1107
- * if at least one of the predicates returns `true`.
1108
- *
1109
- * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the
1110
- * union of their target types (`B | C`).
1111
- *
1112
- * @example
1113
- * ```ts
1114
- * import * as assert from "node:assert"
1115
- * import { Predicate } from "effect"
1116
- *
1117
- * const isString = (u: unknown): u is string => typeof u === "string"
1118
- * const isNumber = (u: unknown): u is number => typeof u === "number"
1119
- *
1120
- * const isStringOrNumber = Predicate.or(isString, isNumber)
1121
- *
1122
- * assert.strictEqual(isStringOrNumber("hello"), true)
1123
- * assert.strictEqual(isStringOrNumber(123), true)
1124
- * assert.strictEqual(isStringOrNumber(null), false)
1125
- *
1126
- * const value: unknown = "world"
1127
- * if (isStringOrNumber(value)) {
1128
- * // value is narrowed to string | number
1129
- * console.log(value)
1130
- * }
1131
- * ```
1132
- *
1133
- * @category combinators
1134
- * @since 2.0.0
1135
- */
1136
- export const or: {
1137
- <A, C extends A>(that: Refinement<A, C>): <B extends A>(self: Refinement<A, B>) => Refinement<A, B | C>
1138
- <A, B extends A, C extends A>(self: Refinement<A, B>, that: Refinement<A, C>): Refinement<A, B | C>
1139
- <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>
1140
- <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>
1141
- } = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) || that(a))
1142
-
1143
- /**
1144
- * Combines two predicates with a logical "AND". The resulting predicate returns `true`
1145
- * only if both of the predicates return `true`.
1146
- *
1147
- * If both predicates are `Refinement`s, the resulting predicate is a `Refinement` to the
1148
- * intersection of their target types (`B & C`).
1149
- *
1150
- * @example
1151
- * ```ts
1152
- * import * as assert from "node:assert"
1153
- * import { Predicate } from "effect"
1154
- *
1155
- * type Person = { name: string }
1156
- * type Employee = { id: number }
1157
- *
1158
- * const hasName = (u: unknown): u is Person => Predicate.hasProperty(u, "name") && typeof (u as any).name === "string"
1159
- * const hasId = (u: unknown): u is Employee => Predicate.hasProperty(u, "id") && typeof (u as any).id === "number"
1160
- *
1161
- * const isPersonAndEmployee = Predicate.and(hasName, hasId)
1162
- *
1163
- * const val: unknown = { name: "Alice", id: 123 }
1164
- * if (isPersonAndEmployee(val)) {
1165
- * // val is narrowed to Person & Employee
1166
- * assert.strictEqual(val.name, "Alice")
1167
- * assert.strictEqual(val.id, 123)
1168
- * }
1169
- *
1170
- * assert.strictEqual(isPersonAndEmployee({ name: "Bob" }), false) // Missing id
1171
- * assert.strictEqual(isPersonAndEmployee({ id: 456 }), false) // Missing name
1172
- * ```
1173
- *
1174
- * @category combinators
1175
- * @since 2.0.0
1176
- */
1177
- export const and: {
1178
- <A, C extends A>(that: Refinement<A, C>): <B extends A>(self: Refinement<A, B>) => Refinement<A, B & C>
1179
- <A, B extends A, C extends A>(self: Refinement<A, B>, that: Refinement<A, C>): Refinement<A, B & C>
1180
- <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>
1181
- <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>
1182
- } = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) && that(a))
1183
-
1184
- /**
1185
- * Combines two predicates with a logical "XOR" (exclusive OR). The resulting predicate
1186
- * returns `true` if one of the predicates returns `true`, but not both.
1187
- *
1188
- * @example
1189
- * ```ts
1190
- * import * as assert from "node:assert"
1191
- * import { Predicate } from "effect"
1192
- *
1193
- * const isPositive = (n: number) => n > 0
1194
- * const isEven = (n: number) => n % 2 === 0
1195
- *
1196
- * const isPositiveXorEven = Predicate.xor(isPositive, isEven)
1197
- *
1198
- * assert.strictEqual(isPositiveXorEven(4), false) // both true -> false
1199
- * assert.strictEqual(isPositiveXorEven(3), true) // one true -> true
1200
- * assert.strictEqual(isPositiveXorEven(-2), true) // one true -> true
1201
- * assert.strictEqual(isPositiveXorEven(-1), false) // both false -> false
1202
- * ```
1203
- *
1204
- * @category combinators
1205
- * @since 2.0.0
1206
- */
1207
- export const xor: {
1208
- <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>
1209
- <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>
1210
- } = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) !== that(a))
1211
-
1212
- /**
1213
- * Combines two predicates with a logical "EQV" (equivalence). The resulting predicate
1214
- * returns `true` if both predicates return the same boolean value (both `true` or both `false`).
1215
- *
1216
- * @example
1217
- * ```ts
1218
- * import * as assert from "node:assert"
1219
- * import { Predicate } from "effect"
1220
- *
1221
- * const isPositive = (n: number) => n > 0
1222
- * const isEven = (n: number) => n % 2 === 0
1223
- *
1224
- * const isPositiveEqvEven = Predicate.eqv(isPositive, isEven)
1225
- *
1226
- * assert.strictEqual(isPositiveEqvEven(4), true) // both true -> true
1227
- * assert.strictEqual(isPositiveEqvEven(3), false) // different -> false
1228
- * assert.strictEqual(isPositiveEqvEven(-2), false) // different -> false
1229
- * assert.strictEqual(isPositiveEqvEven(-1), true) // both false -> true
1230
- * ```
1231
- *
1232
- * @category combinators
1233
- * @since 2.0.0
1234
- */
1235
- export const eqv: {
1236
- <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>
1237
- <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>
1238
- } = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) === that(a))
1239
-
1240
- /**
1241
- * Creates a predicate that represents a logical "if-then" rule.
1242
- *
1243
- * Think of it as a conditional promise: **"If `antecedent` holds true, then I promise `consequent` will also be true."**
1244
- *
1245
- * This function is invaluable for defining complex validation logic where one condition dictates another.
1246
- *
1247
- * ### How It Works
1248
- *
1249
- * The rule only fails (returns `false`) when the "if" part is `true`, but the "then" part is `false`.
1250
- * In all other cases, the promise is considered kept, and the result is `true`.
1251
- *
1252
- * This includes the concept of **"vacuous truth"**: if the "if" part is `false`, the rule doesn't apply,
1253
- * so the promise isn't broken, and the result is `true`. (e.g., "If it rains, I'll bring an umbrella."
1254
- * If it doesn't rain, you haven't broken your promise, no matter what).
1255
- *
1256
- * ### Key Details
1257
- *
1258
- * - **Logical Equivalence**: `implies(p, q)` is the same as `not(p).or(q)`, or simply `!p || q`
1259
- * in plain JavaScript. This can be a helpful way to reason about its behavior.
1260
- *
1261
- * - **Type-Safety Warning**: This function always returns a `Predicate`, never a type-narrowing
1262
- * `Refinement`. A `true` result doesn't guarantee the `consequent` passed (it could be `true`
1263
- * simply because the `antecedent` was `false`), so it cannot be used to safely narrow a type.
1264
- *
1265
- * @example
1266
- * ```ts
1267
- * // Rule: A user can only be an admin if they also belong to the "staff" group.
1268
- * import * as assert from "node:assert"
1269
- * import { Predicate } from "effect"
1270
- *
1271
- * type User = {
1272
- * isStaff: boolean
1273
- * isAdmin: boolean
1274
- * }
1275
- *
1276
- * const isValidUserPermission = Predicate.implies(
1277
- * // antecedent: "if" the user is an admin...
1278
- * (user: User) => user.isAdmin,
1279
- * // consequent: "then" they must be staff.
1280
- * (user: User) => user.isStaff
1281
- * )
1282
- *
1283
- * // A non-admin who is not staff. Rule doesn't apply (antecedent is false).
1284
- * assert.strictEqual(isValidUserPermission({ isStaff: false, isAdmin: false }), true)
1285
- *
1286
- * // A staff member who is not an admin. Rule doesn't apply (antecedent is false).
1287
- * assert.strictEqual(isValidUserPermission({ isStaff: true, isAdmin: false }), true)
1288
- *
1289
- * // An admin who is also staff. The rule was followed.
1290
- * assert.strictEqual(isValidUserPermission({ isStaff: true, isAdmin: true }), true)
1291
- *
1292
- * // An admin who is NOT staff. The rule was broken!
1293
- * assert.strictEqual(isValidUserPermission({ isStaff: false, isAdmin: true }), false)
1294
- * ```
1295
- *
1296
- * @category combinators
1297
- * @since 2.0.0
1298
- */
1299
- export const implies: {
1300
- <A>(consequent: Predicate<A>): (antecedent: Predicate<A>) => Predicate<A>
1301
- <A>(antecedent: Predicate<A>, consequent: Predicate<A>): Predicate<A>
1302
- } = dual(
1303
- 2,
1304
- <A>(antecedent: Predicate<A>, consequent: Predicate<A>): Predicate<A> => (a) => antecedent(a) ? consequent(a) : true
1305
- )
1306
-
1307
- /**
1308
- * Combines two predicates with a logical "NOR" (negated OR). The resulting predicate
1309
- * returns `true` only if both predicates return `false`.
1310
- * This is equivalent to `not(or(p, q))`.
1311
- *
1312
- * @category combinators
1313
- * @since 2.0.0
1314
- */
1315
- export const nor: {
1316
- <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>
1317
- <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>
1318
- } = dual(
1319
- 2,
1320
- <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => !(self(a) || that(a))
1321
- )
1322
-
1323
- /**
1324
- * Combines two predicates with a logical "NAND" (negated AND). The resulting predicate
1325
- * returns `true` if at least one of the predicates returns `false`.
1326
- * This is equivalent to `not(and(p, q))`.
1327
- *
1328
- * @category combinators
1329
- * @since 2.0.0
1330
- */
1331
- export const nand: {
1332
- <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>
1333
- <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>
1334
- } = dual(
1335
- 2,
1336
- <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => !(self(a) && that(a))
1337
- )
1338
-
1339
- /**
1340
- * Takes an iterable of predicates and returns a new predicate. The new predicate
1341
- * returns `true` if all predicates in the collection return `true` for a given value.
1342
- *
1343
- * This is like `Array.prototype.every` but for a collection of predicates.
1344
- *
1345
- * @example
1346
- * ```ts
1347
- * import * as assert from "node:assert"
1348
- * import { Predicate } from "effect"
1349
- *
1350
- * const isPositive = (n: number) => n > 0
1351
- * const isEven = (n: number) => n % 2 === 0
1352
- *
1353
- * const isPositiveAndEven = Predicate.every([isPositive, isEven])
1354
- *
1355
- * assert.strictEqual(isPositiveAndEven(4), true)
1356
- * assert.strictEqual(isPositiveAndEven(3), false)
1357
- * assert.strictEqual(isPositiveAndEven(-2), false)
1358
- * ```
1359
- *
1360
- * @category elements
1361
- * @since 2.0.0
1362
- * @see some
1363
- */
1364
- export const every = <A>(collection: Iterable<Predicate<A>>): Predicate<A> => (a: A) => {
1365
- for (const p of collection) {
1366
- if (!p(a)) {
1367
- return false
1368
- }
1369
- }
1370
- return true
1371
- }
1372
-
1373
- /**
1374
- * Takes an iterable of predicates and returns a new predicate. The new predicate
1375
- * returns `true` if at least one predicate in the collection returns `true` for a given value.
1376
- *
1377
- * This is like `Array.prototype.some` but for a collection of predicates.
1378
- *
1379
- * @example
1380
- * ```ts
1381
- * import * as assert from "node:assert"
1382
- * import { Predicate } from "effect"
1383
- *
1384
- * const isNegative = (n: number) => n < 0
1385
- * const isOdd = (n: number) => n % 2 !== 0
1386
- *
1387
- * const isNegativeOrOdd = Predicate.some([isNegative, isOdd])
1388
- *
1389
- * assert.strictEqual(isNegativeOrOdd(-2), true) // isNegative is true
1390
- * assert.strictEqual(isNegativeOrOdd(3), true) // isOdd is true
1391
- * assert.strictEqual(isNegativeOrOdd(4), false) // both are false
1392
- * ```
1393
- *
1394
- * @category elements
1395
- * @since 2.0.0
1396
- * @see every
1397
- */
1398
- export const some = <A>(collection: Iterable<Predicate<A>>): Predicate<A> => (a) => {
1399
- for (const p of collection) {
1400
- if (p(a)) {
1401
- return true
1402
- }
1403
- }
1404
- return false
1405
- }