effect-app 1.31.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (310) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/_cjs/Array.cjs +132 -0
  3. package/_cjs/Array.cjs.map +1 -0
  4. package/_cjs/Chunk.cjs +128 -0
  5. package/_cjs/Chunk.cjs.map +1 -0
  6. package/_cjs/Config/SecretURL.cjs +3 -3
  7. package/_cjs/Config/SecretURL.cjs.map +1 -1
  8. package/_cjs/Config/internal/configSecretURL.cjs +2 -2
  9. package/_cjs/Config/internal/configSecretURL.cjs.map +1 -1
  10. package/_cjs/Context.cjs +243 -0
  11. package/_cjs/Context.cjs.map +1 -0
  12. package/_cjs/Dictionary.cjs +522 -0
  13. package/_cjs/Dictionary.cjs.map +1 -0
  14. package/_cjs/Effect.cjs +202 -0
  15. package/_cjs/Effect.cjs.map +1 -0
  16. package/_cjs/Function.cjs +107 -0
  17. package/_cjs/Function.cjs.map +1 -0
  18. package/_cjs/NonEmptySet.cjs +26 -0
  19. package/_cjs/NonEmptySet.cjs.map +1 -0
  20. package/_cjs/NonEmptySetAspects.cjs +17 -0
  21. package/_cjs/NonEmptySetAspects.cjs.map +1 -0
  22. package/_cjs/NonEmptySetBase.cjs +82 -0
  23. package/_cjs/NonEmptySetBase.cjs.map +1 -0
  24. package/_cjs/Object.cjs +24 -0
  25. package/_cjs/Object.cjs.map +1 -0
  26. package/_cjs/Operations.cjs +1 -1
  27. package/_cjs/Option.cjs +88 -0
  28. package/_cjs/Option.cjs.map +1 -0
  29. package/_cjs/Prelude.cjs +51 -0
  30. package/_cjs/Prelude.cjs.map +1 -0
  31. package/_cjs/Prelude.code.cjs +51 -0
  32. package/_cjs/Prelude.code.cjs.map +1 -0
  33. package/_cjs/Pure.cjs +39 -36
  34. package/_cjs/Pure.cjs.map +1 -1
  35. package/_cjs/Schema/Class.cjs +61 -0
  36. package/_cjs/Schema/Class.cjs.map +1 -0
  37. package/_cjs/Schema/FastCheck.cjs +39 -0
  38. package/_cjs/Schema/FastCheck.cjs.map +1 -0
  39. package/_cjs/Schema/Methods.cjs +6 -0
  40. package/_cjs/Schema/Methods.cjs.map +1 -0
  41. package/_cjs/Schema/brand.cjs +17 -0
  42. package/_cjs/Schema/brand.cjs.map +1 -0
  43. package/_cjs/Schema/email.cjs +20 -0
  44. package/_cjs/Schema/email.cjs.map +1 -0
  45. package/_cjs/Schema/ext.cjs +174 -0
  46. package/_cjs/Schema/ext.cjs.map +1 -0
  47. package/_cjs/Schema/moreStrings.cjs +124 -0
  48. package/_cjs/Schema/moreStrings.cjs.map +1 -0
  49. package/_cjs/Schema/numbers.cjs +52 -0
  50. package/_cjs/Schema/numbers.cjs.map +1 -0
  51. package/_cjs/Schema/phoneNumber.cjs +22 -0
  52. package/_cjs/Schema/phoneNumber.cjs.map +1 -0
  53. package/_cjs/Schema/schema.cjs +15 -0
  54. package/_cjs/Schema/schema.cjs.map +1 -0
  55. package/_cjs/Schema/strings.cjs +32 -0
  56. package/_cjs/Schema/strings.cjs.map +1 -0
  57. package/_cjs/Schema.cjs +334 -0
  58. package/_cjs/Schema.cjs.map +1 -0
  59. package/_cjs/Set.cjs +567 -0
  60. package/_cjs/Set.cjs.map +1 -0
  61. package/_cjs/Struct.cjs +51 -0
  62. package/_cjs/Struct.cjs.map +1 -0
  63. package/_cjs/Tag.cjs +25 -0
  64. package/_cjs/Tag.cjs.map +1 -0
  65. package/_cjs/Unify.cjs +40 -0
  66. package/_cjs/Unify.cjs.map +1 -0
  67. package/_cjs/_ext/misc.cjs +16 -16
  68. package/_cjs/_ext/misc.cjs.map +1 -1
  69. package/_cjs/_ext/ord.ext.cjs +52 -0
  70. package/_cjs/_ext/ord.ext.cjs.map +1 -0
  71. package/_cjs/builtin.cjs +6 -0
  72. package/_cjs/builtin.cjs.map +1 -0
  73. package/_cjs/client/clientFor.cjs +5 -3
  74. package/_cjs/client/clientFor.cjs.map +1 -1
  75. package/_cjs/client/config.cjs +4 -4
  76. package/_cjs/client/config.cjs.map +1 -1
  77. package/_cjs/client/errors.cjs +9 -9
  78. package/_cjs/client/errors.cjs.map +1 -1
  79. package/_cjs/http/http-client.cjs +35 -0
  80. package/_cjs/http/http-client.cjs.map +1 -0
  81. package/_cjs/ids.cjs +5 -5
  82. package/_cjs/ids.cjs.map +1 -1
  83. package/_cjs/index.cjs +1 -1
  84. package/_cjs/lib.cjs +178 -9
  85. package/_cjs/lib.cjs.map +1 -1
  86. package/_cjs/logger.cjs +1 -1
  87. package/_cjs/transform.cjs +45 -0
  88. package/_cjs/transform.cjs.map +1 -0
  89. package/_cjs/utils/effectify.cjs +25 -0
  90. package/_cjs/utils/effectify.cjs.map +1 -0
  91. package/_cjs/utils/extend.cjs +17 -0
  92. package/_cjs/utils/extend.cjs.map +1 -0
  93. package/_cjs/utils/logger.cjs +23 -0
  94. package/_cjs/utils/logger.cjs.map +1 -0
  95. package/_cjs/utils.cjs +431 -4
  96. package/_cjs/utils.cjs.map +1 -1
  97. package/_cjs/validation/validators.cjs +32 -0
  98. package/_cjs/validation/validators.cjs.map +1 -0
  99. package/_cjs/validation.cjs +45 -0
  100. package/_cjs/validation.cjs.map +1 -0
  101. package/dist/Array.d.ts +64 -0
  102. package/dist/Array.d.ts.map +1 -0
  103. package/dist/Array.js +89 -0
  104. package/dist/Chunk.d.ts +68 -0
  105. package/dist/Chunk.d.ts.map +1 -0
  106. package/dist/Chunk.js +93 -0
  107. package/dist/Config/SecretURL.d.ts +3 -3
  108. package/dist/Config/SecretURL.d.ts.map +1 -1
  109. package/dist/Config/SecretURL.js +2 -2
  110. package/dist/Config/internal/configSecretURL.js +2 -2
  111. package/dist/Context.d.ts +55 -0
  112. package/dist/Context.d.ts.map +1 -0
  113. package/dist/Context.js +204 -0
  114. package/dist/Dictionary.d.ts +260 -0
  115. package/dist/Dictionary.d.ts.map +1 -0
  116. package/dist/Dictionary.js +448 -0
  117. package/dist/Effect.d.ts +115 -0
  118. package/dist/Effect.d.ts.map +1 -0
  119. package/dist/Effect.js +153 -0
  120. package/dist/Function.d.ts +72 -0
  121. package/dist/Function.d.ts.map +1 -0
  122. package/dist/Function.js +71 -0
  123. package/dist/Inputify.type.d.ts +1 -1
  124. package/dist/Inputify.type.d.ts.map +1 -1
  125. package/dist/NonEmptySet.d.ts +3 -0
  126. package/dist/NonEmptySet.d.ts.map +1 -0
  127. package/dist/NonEmptySet.js +3 -0
  128. package/dist/NonEmptySetAspects.d.ts +2 -0
  129. package/dist/NonEmptySetAspects.d.ts.map +1 -0
  130. package/dist/NonEmptySetAspects.js +2 -0
  131. package/dist/NonEmptySetBase.d.ts +39 -0
  132. package/dist/NonEmptySetBase.d.ts.map +1 -0
  133. package/dist/NonEmptySetBase.js +63 -0
  134. package/dist/Object.d.ts +7 -0
  135. package/dist/Object.d.ts.map +1 -0
  136. package/dist/Object.js +7 -0
  137. package/dist/Operations.d.ts +2 -2
  138. package/dist/Operations.js +1 -1
  139. package/dist/Option.d.ts +39 -0
  140. package/dist/Option.d.ts.map +1 -0
  141. package/dist/Option.js +55 -0
  142. package/dist/Prelude.code.d.ts +24 -0
  143. package/dist/Prelude.code.d.ts.map +1 -0
  144. package/dist/Prelude.code.js +23 -0
  145. package/dist/Prelude.d.ts +163 -0
  146. package/dist/Prelude.d.ts.map +1 -0
  147. package/dist/Prelude.js +23 -0
  148. package/dist/Pure.d.ts +13 -12
  149. package/dist/Pure.d.ts.map +1 -1
  150. package/dist/Pure.js +18 -17
  151. package/dist/Schema/Class.d.ts +45 -0
  152. package/dist/Schema/Class.d.ts.map +1 -0
  153. package/dist/Schema/Class.js +50 -0
  154. package/dist/Schema/FastCheck.d.ts +10 -0
  155. package/dist/Schema/FastCheck.d.ts.map +1 -0
  156. package/dist/Schema/FastCheck.js +12 -0
  157. package/dist/Schema/Methods.d.ts +6 -0
  158. package/dist/Schema/Methods.d.ts.map +1 -0
  159. package/dist/Schema/Methods.js +2 -0
  160. package/dist/Schema/brand.d.ts +35 -0
  161. package/dist/Schema/brand.d.ts.map +1 -0
  162. package/dist/Schema/brand.js +7 -0
  163. package/dist/Schema/email.d.ts +9 -0
  164. package/dist/Schema/email.d.ts.map +1 -0
  165. package/dist/Schema/email.js +12 -0
  166. package/dist/Schema/ext.d.ts +89 -0
  167. package/dist/Schema/ext.d.ts.map +1 -0
  168. package/dist/Schema/ext.js +111 -0
  169. package/dist/Schema/moreStrings.d.ts +109 -0
  170. package/dist/Schema/moreStrings.d.ts.map +1 -0
  171. package/dist/Schema/moreStrings.js +108 -0
  172. package/dist/Schema/numbers.d.ts +46 -0
  173. package/dist/Schema/numbers.d.ts.map +1 -0
  174. package/dist/Schema/numbers.js +28 -0
  175. package/dist/Schema/phoneNumber.d.ts +9 -0
  176. package/dist/Schema/phoneNumber.d.ts.map +1 -0
  177. package/dist/Schema/phoneNumber.js +14 -0
  178. package/dist/Schema/schema.d.ts +6 -0
  179. package/dist/Schema/schema.d.ts.map +1 -0
  180. package/dist/Schema/schema.js +5 -0
  181. package/dist/Schema/strings.d.ts +19 -0
  182. package/dist/Schema/strings.d.ts.map +1 -0
  183. package/dist/Schema/strings.js +32 -0
  184. package/dist/{schema.d.ts → Schema.d.ts} +25 -9
  185. package/dist/Schema.d.ts.map +1 -0
  186. package/dist/Schema.js +89 -0
  187. package/dist/Set.d.ts +221 -0
  188. package/dist/Set.d.ts.map +1 -0
  189. package/dist/Set.js +516 -0
  190. package/dist/Struct.d.ts +44 -0
  191. package/dist/Struct.d.ts.map +1 -0
  192. package/dist/Struct.js +29 -0
  193. package/dist/Tag.d.ts +9 -0
  194. package/dist/Tag.d.ts.map +1 -0
  195. package/dist/Tag.js +18 -0
  196. package/dist/Unify.d.ts +43 -0
  197. package/dist/Unify.d.ts.map +1 -0
  198. package/dist/Unify.js +31 -0
  199. package/dist/Widen.type.d.ts +1 -1
  200. package/dist/Widen.type.d.ts.map +1 -1
  201. package/dist/_ext/misc.d.ts +11 -11
  202. package/dist/_ext/misc.d.ts.map +1 -1
  203. package/dist/_ext/misc.js +8 -8
  204. package/dist/_ext/ord.ext.d.ts +23 -0
  205. package/dist/_ext/ord.ext.d.ts.map +1 -0
  206. package/dist/_ext/ord.ext.js +44 -0
  207. package/dist/builtin.d.ts +51 -0
  208. package/dist/builtin.d.ts.map +1 -0
  209. package/dist/builtin.js +2 -0
  210. package/dist/client/clientFor.d.ts +1 -1
  211. package/dist/client/clientFor.d.ts.map +1 -1
  212. package/dist/client/clientFor.js +2 -2
  213. package/dist/client/config.d.ts +1 -1
  214. package/dist/client/config.d.ts.map +1 -1
  215. package/dist/client/config.js +2 -2
  216. package/dist/client/errors.js +1 -1
  217. package/dist/http/http-client.d.ts +43 -0
  218. package/dist/http/http-client.d.ts.map +1 -0
  219. package/dist/http/http-client.js +30 -0
  220. package/dist/ids.d.ts +3 -3
  221. package/dist/ids.d.ts.map +1 -1
  222. package/dist/ids.js +2 -2
  223. package/dist/index.d.ts +1 -1
  224. package/dist/index.d.ts.map +1 -1
  225. package/dist/index.js +2 -2
  226. package/dist/lib.d.ts +22 -4
  227. package/dist/lib.d.ts.map +1 -1
  228. package/dist/lib.js +20 -5
  229. package/dist/logger.d.ts.map +1 -1
  230. package/dist/logger.js +2 -2
  231. package/dist/transform.d.ts +12 -0
  232. package/dist/transform.d.ts.map +1 -0
  233. package/dist/transform.js +39 -0
  234. package/dist/utils/effectify.d.ts +210 -0
  235. package/dist/utils/effectify.d.ts.map +1 -0
  236. package/dist/utils/effectify.js +19 -0
  237. package/dist/utils/extend.d.ts +3 -0
  238. package/dist/utils/extend.d.ts.map +1 -0
  239. package/dist/utils/extend.js +9 -0
  240. package/dist/utils/logger.d.ts +12 -0
  241. package/dist/utils/logger.d.ts.map +1 -0
  242. package/dist/utils/logger.js +15 -0
  243. package/dist/utils.d.ts +192 -1
  244. package/dist/utils.d.ts.map +1 -1
  245. package/dist/utils.js +332 -2
  246. package/dist/validation/validators.d.ts +11 -0
  247. package/dist/validation/validators.d.ts.map +1 -0
  248. package/dist/validation/validators.js +26 -0
  249. package/dist/validation.d.ts +13 -0
  250. package/dist/validation.d.ts.map +1 -0
  251. package/dist/validation.js +14 -0
  252. package/package.json +360 -10
  253. package/src/Array.ts +127 -0
  254. package/src/Chunk.ts +112 -0
  255. package/src/Config/SecretURL.ts +3 -3
  256. package/src/Config/internal/configSecretURL.ts +1 -1
  257. package/src/Context.ts +293 -0
  258. package/src/Dictionary.ts +669 -0
  259. package/src/Effect.ts +265 -0
  260. package/src/Function.ts +175 -0
  261. package/src/Inputify.type.ts +1 -1
  262. package/src/NonEmptySet.ts +3 -0
  263. package/src/NonEmptySetAspects.ts +1 -0
  264. package/src/NonEmptySetBase.ts +109 -0
  265. package/src/Object.ts +19 -0
  266. package/src/Operations.ts +1 -1
  267. package/src/Option.ts +82 -0
  268. package/src/Prelude.code.ts +26 -0
  269. package/src/Prelude.ts +220 -0
  270. package/src/Pure.ts +37 -30
  271. package/src/Schema/Class.ts +225 -0
  272. package/src/Schema/FastCheck.ts +23 -0
  273. package/src/Schema/Methods.ts +8 -0
  274. package/src/Schema/brand.ts +50 -0
  275. package/src/Schema/email.ts +22 -0
  276. package/src/Schema/ext.ts +273 -0
  277. package/src/Schema/moreStrings.ts +260 -0
  278. package/src/Schema/numbers.ts +83 -0
  279. package/src/Schema/phoneNumber.ts +24 -0
  280. package/src/Schema/schema.ts +6 -0
  281. package/src/Schema/strings.ts +60 -0
  282. package/src/{schema.ts → Schema.ts} +52 -20
  283. package/src/Set.ts +674 -0
  284. package/src/Struct.ts +54 -0
  285. package/src/Tag.ts +20 -0
  286. package/src/Unify.ts +56 -0
  287. package/src/Widen.type.ts +1 -1
  288. package/src/_ext/misc.ts +22 -22
  289. package/src/_ext/ord.ext.ts +49 -0
  290. package/src/builtin.ts +64 -0
  291. package/src/client/clientFor.ts +1 -1
  292. package/src/client/config.ts +1 -1
  293. package/src/client/errors.ts +1 -1
  294. package/src/http/http-client.ts +73 -0
  295. package/src/ids.ts +3 -3
  296. package/src/index.ts +1 -1
  297. package/src/lib.ts +88 -4
  298. package/src/logger.ts +1 -1
  299. package/src/transform.ts +80 -0
  300. package/src/utils/effectify.ts +259 -0
  301. package/src/utils/extend.ts +9 -0
  302. package/src/utils/logger.ts +24 -0
  303. package/src/utils.ts +805 -1
  304. package/src/validation/validators.ts +32 -0
  305. package/src/validation.ts +18 -0
  306. package/tsconfig.src.json +1 -8
  307. package/_cjs/schema.cjs +0 -110
  308. package/_cjs/schema.cjs.map +0 -1
  309. package/dist/schema.d.ts.map +0 -1
  310. package/dist/schema.js +0 -73
@@ -0,0 +1,669 @@
1
+ // ets_tracing: off
2
+
3
+ import type * as Either from "effect/Either"
4
+ import * as A from "./Array.js"
5
+ import { pipe, type Predicate, type Refinement, tuple } from "./Function.js"
6
+ import * as O from "./Option.js"
7
+ import type { PredicateWithIndex, RefinementWithIndex } from "./utils.js"
8
+
9
+ export type MutableRecord<K extends string, T> = Record<K, T>
10
+
11
+ /* adapted from https://github.com/gcanti/fp-ts */
12
+
13
+ export type Dictionary<T> = {
14
+ readonly [P in string]: T
15
+ }
16
+
17
+ // /**
18
+ // * Build a readonly record from a mutable version
19
+ // */
20
+ // export function fromMutable<A>(r: MutableRecord<string, A>): Dictionary<A> {
21
+ // return Object.assign({}, r)
22
+ // }
23
+
24
+ // /**
25
+ // * Converts the record to a mutable version
26
+ // */
27
+ // export function toMutable<A>(r: Dictionary<A>): MutableRecord<string, A> {
28
+ // return Object.assign({}, r)
29
+ // }
30
+
31
+ /**
32
+ * Calculate the number of key/value pairs in a record
33
+ */
34
+ export function size(r: Dictionary<unknown>): number {
35
+ return Object.keys(r).length
36
+ }
37
+
38
+ /**
39
+ * Test whether a record is empty
40
+ */
41
+ export function isEmpty(r: Dictionary<unknown>): boolean {
42
+ return Object.keys(r).length === 0
43
+ }
44
+
45
+ /**
46
+ * Extract record keys
47
+ */
48
+ export function keys(r: Dictionary<unknown>): ReadonlyArray<string> {
49
+ return Object.keys(r).sort() as any
50
+ }
51
+
52
+ /**
53
+ * Extract record values
54
+ */
55
+ export function values<V>(r: Dictionary<V>): ReadonlyArray<V> {
56
+ return Object
57
+ .keys(r)
58
+ .sort()
59
+ .map((s) => r[s]!)
60
+ }
61
+
62
+ /**
63
+ * Map a record into an array
64
+ */
65
+ export function collect<A, B>(
66
+ f: (k: string, a: A) => B
67
+ ): (r: Dictionary<A>) => ReadonlyArray<B> {
68
+ return (r) => collect_(r, f)
69
+ }
70
+
71
+ /**
72
+ * Map a record into an array
73
+ */
74
+ export function collect_<A, B>(
75
+ r: Dictionary<A>,
76
+ f: (k: string, a: A) => B
77
+ ): ReadonlyArray<B> {
78
+ const out: Array<B> = []
79
+ for (const key of keys(r)) {
80
+ out.push(f(key, r[key]!))
81
+ }
82
+ return out
83
+ }
84
+
85
+ /**
86
+ * Insert or replace a key/value pair in a record
87
+ */
88
+ export function insertAt<A>(k: string, a: A): (r: Dictionary<A>) => Dictionary<A> {
89
+ return (r) => insertAt_(r, k, a)
90
+ }
91
+
92
+ /**
93
+ * Insert or replace a key/value pair in a record
94
+ */
95
+ export function insertAt_<A>(r: Dictionary<A>, k: string, a: A): Dictionary<A> {
96
+ if (r[k] === a) {
97
+ return r
98
+ }
99
+ const out: MutableRecord<string, A> = Object.assign({}, r)
100
+ out[k] = a
101
+ return out
102
+ }
103
+
104
+ /**
105
+ * Check if k is a key
106
+ */
107
+ export function hasOwnProperty(r: Dictionary<unknown>, k: string): boolean {
108
+ return Object.prototype.hasOwnProperty.call(r, k)
109
+ }
110
+
111
+ /**
112
+ * Delete a key
113
+ */
114
+ export function deleteAt(k: string): <A>(r: Dictionary<A>) => Dictionary<A> {
115
+ return <A>(r: Dictionary<A>) => deleteAt_(r, k)
116
+ }
117
+
118
+ /**
119
+ * Delete a key
120
+ */
121
+ export function deleteAt_<A>(r: Dictionary<A>, k: string): Dictionary<A> {
122
+ if (!Object.prototype.hasOwnProperty.call(r, k)) {
123
+ return r
124
+ }
125
+ const out: MutableRecord<string, A> = Object.assign({}, r)
126
+ delete out[k]
127
+ return out
128
+ }
129
+
130
+ /**
131
+ * Update a key value pair
132
+ */
133
+ export function updateAt<A>(
134
+ k: string,
135
+ a: A
136
+ ): (r: Dictionary<A>) => O.Option<Dictionary<A>> {
137
+ return (r: Dictionary<A>) => updateAt_(r, k, a)
138
+ }
139
+
140
+ /**
141
+ * Update a key value pair
142
+ */
143
+ export function updateAt_<A>(
144
+ r: Dictionary<A>,
145
+ k: string,
146
+ a: A
147
+ ): O.Option<Dictionary<A>> {
148
+ if (!hasOwnProperty(r, k)) {
149
+ return O.none()
150
+ }
151
+ if (r[k] === a) {
152
+ return O.some(r)
153
+ }
154
+ const out: MutableRecord<string, A> = Object.assign({}, r)
155
+ out[k] = a
156
+ return O.some(out)
157
+ }
158
+
159
+ /**
160
+ * Modify the value at key k with f
161
+ */
162
+ export function modifyAt<A>(
163
+ k: string,
164
+ f: (a: A) => A
165
+ ): (r: Dictionary<A>) => O.Option<Dictionary<A>> {
166
+ return (r: Dictionary<A>) => modifyAt_(r, k, f)
167
+ }
168
+
169
+ /**
170
+ * Modify the value at key k with f
171
+ */
172
+ export function modifyAt_<A>(
173
+ r: Dictionary<A>,
174
+ k: string,
175
+ f: (a: A) => A
176
+ ): O.Option<Dictionary<A>> {
177
+ if (!hasOwnProperty(r, k)) {
178
+ return O.none()
179
+ }
180
+ const out: MutableRecord<string, A> = Object.assign({}, r)
181
+ out[k] = f(r[k]!)
182
+ return O.some(out)
183
+ }
184
+
185
+ /**
186
+ * Delete a key and value from a map, returning the value as well as the subsequent map
187
+ */
188
+ export function pop(
189
+ k: string
190
+ ): <A>(r: Dictionary<A>) => O.Option<readonly [A, Dictionary<A>]> {
191
+ return (r) => pop_(r, k)
192
+ }
193
+
194
+ /**
195
+ * Delete a key and value from a map, returning the value as well as the subsequent map
196
+ */
197
+ export function pop_<A>(
198
+ r: Dictionary<A>,
199
+ k: string
200
+ ): O.Option<readonly [A, Dictionary<A>]> {
201
+ const deleteAtk = deleteAt(k)
202
+ const oa = lookup_(r, k)
203
+ return O.isNone(oa) ? O.none() : O.some(tuple(oa.value, deleteAtk(r)))
204
+ }
205
+
206
+ /**
207
+ * Lookup the value for a key in a record
208
+ */
209
+ export function lookup_<A>(r: Dictionary<A>, k: string): O.Option<A> {
210
+ return Object.prototype.hasOwnProperty.call(r, k) ? O.some(r[k]!) : O.none()
211
+ }
212
+
213
+ /**
214
+ * Lookup the value for a key in a record
215
+ */
216
+ export function lookup(k: string): <A>(r: Dictionary<A>) => O.Option<A> {
217
+ return (r) => (Object.prototype.hasOwnProperty.call(r, k) ? O.some(r[k]!) : O.none())
218
+ }
219
+
220
+ /**
221
+ * Empty record
222
+ */
223
+ export const empty: Dictionary<never> = {}
224
+
225
+ /**
226
+ * Map a record passing the keys to the iterating function
227
+ */
228
+ export function mapWithIndex<A, B>(
229
+ f: (k: string, a: A) => B
230
+ ): (fa: Dictionary<A>) => Dictionary<B> {
231
+ return (fa) => mapWithIndex_(fa, f)
232
+ }
233
+
234
+ /**
235
+ * Map a record passing the keys to the iterating function
236
+ */
237
+ export function mapWithIndex_<A, B>(
238
+ fa: Dictionary<A>,
239
+ f: (k: string, a: A) => B
240
+ ): Dictionary<B> {
241
+ const out: MutableRecord<string, B> = {}
242
+ const keys = Object.keys(fa)
243
+ for (const key of keys) {
244
+ out[key] = f(key, fa[key]!)
245
+ }
246
+ return out
247
+ }
248
+
249
+ /**
250
+ * Map a record passing the values to the iterating function
251
+ */
252
+ export function map<A, B>(f: (a: A) => B): (fa: Dictionary<A>) => Dictionary<B> {
253
+ return (fa) => map_(fa, f)
254
+ }
255
+
256
+ /**
257
+ * Map a record passing the values to the iterating function
258
+ */
259
+ export function map_<A, B>(fa: Dictionary<A>, f: (a: A) => B): Dictionary<B> {
260
+ return mapWithIndex_(fa, (_, a) => f(a))
261
+ }
262
+
263
+ /**
264
+ * Reduce the record passing the index toghether with the value to f
265
+ */
266
+ export function reduceWithIndex<A, B>(
267
+ b: B,
268
+ f: (k: string, b: B, a: A) => B
269
+ ): (fa: Dictionary<A>) => B {
270
+ return (fa) => reduceWithIndex_(fa, b, f)
271
+ }
272
+
273
+ /**
274
+ * Reduce the record passing the index toghether with the value to f
275
+ */
276
+ export function reduceWithIndex_<A, B>(
277
+ fa: Dictionary<A>,
278
+ b: B,
279
+ f: (k: string, b: B, a: A) => B
280
+ ): B {
281
+ let out = b
282
+ const keys = Object.keys(fa).sort()
283
+ const len = keys.length
284
+ for (let i = 0; i < len; i++) {
285
+ const k = keys[i]!
286
+ out = f(k, out, fa[k]!)
287
+ }
288
+ return out
289
+ }
290
+
291
+ /**
292
+ * Reduce the record passing the index toghether with the value to f
293
+ *
294
+ * Inverted order
295
+ */
296
+ export function reduceRightWithIndex<A, B>(
297
+ b: B,
298
+ f: (k: string, a: A, b: B) => B
299
+ ): (fa: Dictionary<A>) => B {
300
+ return (fa) => reduceRightWithIndex_(fa, b, f)
301
+ }
302
+
303
+ /**
304
+ * Reduce the record passing the index toghether with the value to f
305
+ *
306
+ * Inverted order
307
+ */
308
+ export function reduceRightWithIndex_<A, B>(
309
+ fa: Dictionary<A>,
310
+ b: B,
311
+ f: (k: string, a: A, b: B) => B
312
+ ): B {
313
+ let out = b
314
+ const keys = Object.keys(fa).sort()
315
+ const len = keys.length
316
+ for (let i = len - 1; i >= 0; i--) {
317
+ const k = keys[i]!
318
+ out = f(k, fa[k]!, out)
319
+ }
320
+ return out
321
+ }
322
+
323
+ /**
324
+ * Create a record with one key/value pair
325
+ */
326
+ export function singleton<A>(k: string, a: A): Dictionary<A> {
327
+ return { [k]: a }
328
+ }
329
+
330
+ /**
331
+ * Partition a record using f that also consumes the entry key
332
+ */
333
+ export function partitionMapWithIndex<A, B, C>(
334
+ f: (key: string, a: A) => Either.Either<C, B>
335
+ ): (fa: Dictionary<A>) => readonly [Dictionary<B>, Dictionary<C>] {
336
+ return (fa) => partitionMapWithIndex_(fa, f)
337
+ }
338
+
339
+ /**
340
+ * Partition a record using f that also consumes the entry key
341
+ */
342
+ export function partitionMapWithIndex_<A, B, C>(
343
+ fa: Dictionary<A>,
344
+ f: (key: string, a: A) => Either.Either<C, B>
345
+ ): readonly [Dictionary<B>, Dictionary<C>] {
346
+ const left: MutableRecord<string, B> = {}
347
+ const right: MutableRecord<string, C> = {}
348
+ const keys = Object.keys(fa)
349
+ for (const key of keys) {
350
+ const e = f(key, fa[key]!)
351
+ switch (e._tag) {
352
+ case "Left":
353
+ left[key] = e.left
354
+ break
355
+ case "Right":
356
+ right[key] = e.right
357
+ break
358
+ }
359
+ }
360
+ return tuple(left, right)
361
+ }
362
+
363
+ /**
364
+ * Partition a record using a predicate that also consumes the entry key
365
+ */
366
+ export function partitionWithIndex<A, B extends A>(
367
+ refinementWithIndex: RefinementWithIndex<string, A, B>
368
+ ): (fa: Dictionary<A>) => readonly [Dictionary<A>, Dictionary<B>]
369
+ export function partitionWithIndex<A>(
370
+ predicateWithIndex: PredicateWithIndex<string, A>
371
+ ): (fa: Dictionary<A>) => readonly [Dictionary<A>, Dictionary<A>]
372
+ export function partitionWithIndex<A>(
373
+ predicateWithIndex: PredicateWithIndex<string, A>
374
+ ): (fa: Dictionary<A>) => readonly [Dictionary<A>, Dictionary<A>] {
375
+ return (fa) => partitionWithIndex_(fa, predicateWithIndex)
376
+ }
377
+
378
+ /**
379
+ * Partition a record using a predicate that also consumes the entry key
380
+ */
381
+ export function partitionWithIndex_<A, B extends A>(
382
+ fa: Dictionary<A>,
383
+ refinementWithIndex: RefinementWithIndex<string, A, B>
384
+ ): readonly [Dictionary<A>, Dictionary<B>]
385
+ export function partitionWithIndex_<A>(
386
+ fa: Dictionary<A>,
387
+ predicateWithIndex: PredicateWithIndex<string, A>
388
+ ): readonly [Dictionary<A>, Dictionary<A>]
389
+ export function partitionWithIndex_<A>(
390
+ fa: Dictionary<A>,
391
+ predicateWithIndex: PredicateWithIndex<string, A>
392
+ ): readonly [Dictionary<A>, Dictionary<A>] {
393
+ const left: MutableRecord<string, A> = {}
394
+ const right: MutableRecord<string, A> = {}
395
+ const keys = Object.keys(fa)
396
+ for (const key of keys) {
397
+ const a = fa[key]!
398
+ if (predicateWithIndex(key, a)) {
399
+ right[key] = a
400
+ } else {
401
+ left[key] = a
402
+ }
403
+ }
404
+ return tuple(left, right)
405
+ }
406
+
407
+ /**
408
+ * Filter & map the record entries with f that consumes also the entry index
409
+ */
410
+ export function filterMapWithIndex<A, B>(
411
+ f: (key: string, a: A) => O.Option<B>
412
+ ): (fa: Dictionary<A>) => Dictionary<B>
413
+ export function filterMapWithIndex<A, B>(
414
+ f: (key: string, a: A) => O.Option<B>
415
+ ): (fa: Dictionary<A>) => Dictionary<B> {
416
+ return (fa) => filterMapWithIndex_(fa, f)
417
+ }
418
+
419
+ /**
420
+ * Filter & map the record entries with f that consumes also the entry index
421
+ */
422
+ export function filterMapWithIndex_<A, B>(
423
+ fa: Dictionary<A>,
424
+ f: (key: string, a: A) => O.Option<B>
425
+ ): Dictionary<B> {
426
+ const r: MutableRecord<string, B> = {}
427
+ const keys = Object.keys(fa)
428
+ for (const key of keys) {
429
+ const optionB = f(key, fa[key]!)
430
+ if (O.isSome(optionB)) {
431
+ r[key] = optionB.value
432
+ }
433
+ }
434
+ return r
435
+ }
436
+
437
+ /**
438
+ * Filter the record entries with f that consumes also the entry index
439
+ */
440
+ export function filterWithIndex<A, B extends A>(
441
+ refinementWithIndex: RefinementWithIndex<string, A, B>
442
+ ): (fa: Dictionary<A>) => Dictionary<B>
443
+ export function filterWithIndex<A>(
444
+ predicateWithIndex: PredicateWithIndex<string, A>
445
+ ): (fa: Dictionary<A>) => Dictionary<A>
446
+ export function filterWithIndex<A>(
447
+ predicateWithIndex: PredicateWithIndex<string, A>
448
+ ): (fa: Dictionary<A>) => Dictionary<A> {
449
+ return (fa) => filterWithIndex_(fa, predicateWithIndex)
450
+ }
451
+
452
+ /**
453
+ * Filter the record entries with f that consumes also the entry index
454
+ */
455
+ export function filterWithIndex_<A, B extends A>(
456
+ fa: Dictionary<A>,
457
+ refinementWithIndex: RefinementWithIndex<string, A, B>
458
+ ): Dictionary<B>
459
+ export function filterWithIndex_<A>(
460
+ fa: Dictionary<A>,
461
+ predicateWithIndex: PredicateWithIndex<string, A>
462
+ ): Dictionary<A>
463
+ export function filterWithIndex_<A>(
464
+ fa: Dictionary<A>,
465
+ predicateWithIndex: PredicateWithIndex<string, A>
466
+ ): Dictionary<A> {
467
+ const out: MutableRecord<string, A> = {}
468
+ let changed = false
469
+ for (const key in fa) {
470
+ if (Object.prototype.hasOwnProperty.call(fa, key)) {
471
+ const a = fa[key]!
472
+ if (predicateWithIndex(key, a)) {
473
+ out[key] = a
474
+ } else {
475
+ changed = true
476
+ }
477
+ }
478
+ }
479
+ return changed ? out : fa
480
+ }
481
+
482
+ /**
483
+ * Checks a predicate against all the record entries
484
+ */
485
+ export function every<A>(predicate: Predicate<A>): (r: Dictionary<A>) => boolean {
486
+ return (r) => every_(r, predicate)
487
+ }
488
+
489
+ /**
490
+ * Checks a predicate against all the record entries
491
+ */
492
+ export function every_<A>(r: Dictionary<A>, predicate: Predicate<A>): boolean {
493
+ for (const k in r) {
494
+ if (!predicate(r[k]!)) {
495
+ return false
496
+ }
497
+ }
498
+ return true
499
+ }
500
+
501
+ /**
502
+ * Checks a predicate against some of the record entries
503
+ */
504
+ export function some<A>(predicate: (a: A) => boolean): (r: Dictionary<A>) => boolean {
505
+ return (r) => some_(r, predicate)
506
+ }
507
+
508
+ /**
509
+ * Checks a predicate against some of the record entries
510
+ */
511
+ export function some_<A>(r: Dictionary<A>, predicate: (a: A) => boolean): boolean {
512
+ for (const k in r) {
513
+ if (predicate(r[k]!)) {
514
+ return true
515
+ }
516
+ }
517
+ return false
518
+ }
519
+
520
+ /**
521
+ * Drop the None entries
522
+ */
523
+ export const compact = <A>(fa: Dictionary<O.Option<A>>): Dictionary<A> => {
524
+ const r: MutableRecord<string, A> = {}
525
+ const keys = Object.keys(fa)
526
+ for (const key of keys) {
527
+ const optionA = fa[key]!
528
+ if (O.isSome(optionA)) {
529
+ r[key] = optionA.value
530
+ }
531
+ }
532
+ return r
533
+ }
534
+
535
+ /**
536
+ * Separate the record entries
537
+ */
538
+ export const separate = <A, B>(
539
+ fa: Dictionary<Either.Either<B, A>>
540
+ ): readonly [Dictionary<A>, Dictionary<B>] => {
541
+ const left: MutableRecord<string, A> = {}
542
+ const right: MutableRecord<string, B> = {}
543
+ const keys = Object.keys(fa)
544
+ for (const key of keys) {
545
+ const e = fa[key]!
546
+ switch (e._tag) {
547
+ case "Left":
548
+ left[key] = e.left
549
+ break
550
+ case "Right":
551
+ right[key] = e.right
552
+ break
553
+ }
554
+ }
555
+ return tuple(left, right)
556
+ }
557
+
558
+ /**
559
+ * Filter record entries according to a predicate
560
+ */
561
+ export const filter: {
562
+ <A, B extends A>(refinement: Refinement<A, B>): (fa: Dictionary<A>) => Dictionary<B>
563
+ <A>(predicate: Predicate<A>): (fa: Dictionary<A>) => Dictionary<A>
564
+ } = <A>(predicate: Predicate<A>) => (fa: Dictionary<A>): Dictionary<A> => filter_(fa, predicate)
565
+
566
+ /**
567
+ * Filter record entries according to a predicate
568
+ */
569
+ export const filter_: {
570
+ <A, B extends A>(fa: Dictionary<A>, refinement: Refinement<A, B>): Dictionary<B>
571
+ <A>(fa: Dictionary<A>, predicate: Predicate<A>): Dictionary<A>
572
+ } = <A>(fa: Dictionary<A>, predicate: Predicate<A>): Dictionary<A> => filterWithIndex_(fa, (_, a) => predicate(a))
573
+
574
+ /**
575
+ * Filter & map record entries according to a predicate
576
+ */
577
+ export const filterMap = <A, B>(f: (a: A) => O.Option<B>) => (fa: Dictionary<A>) => filterMap_(fa, f)
578
+
579
+ /**
580
+ * Filter & map record entries according to a predicate
581
+ */
582
+ export const filterMap_ = <A, B>(fa: Dictionary<A>, f: (a: A) => O.Option<B>) =>
583
+ filterMapWithIndex_(fa, (_, a: A) => f(a))
584
+
585
+ /**
586
+ * Partition record entries according to a predicate
587
+ */
588
+ export const partition: {
589
+ <A, B extends A>(refinement: Refinement<A, B>): (
590
+ fa: Dictionary<A>
591
+ ) => readonly [Dictionary<A>, Dictionary<B>]
592
+ <A>(predicate: Predicate<A>): (
593
+ fa: Dictionary<A>
594
+ ) => readonly [Dictionary<A>, Dictionary<A>]
595
+ } = <A>(predicate: Predicate<A>) => (fa: Dictionary<A>): readonly [Dictionary<A>, Dictionary<A>] =>
596
+ partition_(fa, predicate)
597
+
598
+ /**
599
+ * Partition record entries according to a predicate
600
+ */
601
+ export const partition_: {
602
+ <A, B extends A>(fa: Dictionary<A>, refinement: Refinement<A, B>): readonly [Dictionary<A>, Dictionary<B>]
603
+
604
+ <A>(fa: Dictionary<A>, predicate: Predicate<A>): readonly [Dictionary<A>, Dictionary<A>]
605
+ } = <A>(
606
+ fa: Dictionary<A>,
607
+ predicate: Predicate<A>
608
+ ): readonly [Dictionary<A>, Dictionary<A>] => partitionWithIndex_(fa, (_, a) => predicate(a))
609
+
610
+ /**
611
+ * Partition & map record entries
612
+ */
613
+ export const partitionMap: {
614
+ <A, B, C>(f: (a: A) => Either.Either<C, B>): (
615
+ fa: Dictionary<A>
616
+ ) => readonly [Dictionary<B>, Dictionary<C>]
617
+ <A, B, C>(f: (a: A) => Either.Either<C, B>): (
618
+ fa: Dictionary<A>
619
+ ) => readonly [Dictionary<B>, Dictionary<C>]
620
+ } = <A, B, C>(f: (a: A) => Either.Either<C, B>) => (fa: Dictionary<A>) => partitionMap_(fa, f)
621
+
622
+ /**
623
+ * Partition & map record entries
624
+ */
625
+ export const partitionMap_ = <A, B, C>(fa: Dictionary<A>, f: (a: A) => Either.Either<C, B>) =>
626
+ partitionMapWithIndex_(fa, (_, a: A) => f(a))
627
+
628
+ /**
629
+ * Reduce record entries
630
+ */
631
+ export const reduce: <A, B>(b: B, f: (b: B, a: A) => B) => (fa: Dictionary<A>) => B = (b, f) => (fa) =>
632
+ reduce_(fa, b, f)
633
+
634
+ /**
635
+ * Reduce record entries
636
+ */
637
+ export const reduce_: <A, B>(fa: Dictionary<A>, b: B, f: (b: B, a: A) => B) => B = (
638
+ fa,
639
+ b,
640
+ f
641
+ ) => reduceWithIndex_(fa, b, (_, b, a) => f(b, a))
642
+
643
+ /**
644
+ * Reduce record entries in inverted order
645
+ */
646
+ export const reduceRight: <A, B>(
647
+ b: B,
648
+ f: (a: A, b: B) => B
649
+ ) => (fa: Dictionary<A>) => B = (b, f) => (fa) => reduceRight_(fa, b, f)
650
+
651
+ /**
652
+ * Reduce record entries in inverted order
653
+ */
654
+ export const reduceRight_: <A, B>(
655
+ fa: Readonly<MutableRecord<string, A>>,
656
+ b: B,
657
+ f: (a: A, b: B) => B
658
+ ) => B = (fa, b, f) => reduceRightWithIndex_(fa, b, (_, a, b) => f(a, b))
659
+
660
+ /**
661
+ * Converts a record into an array of [key, value]
662
+ */
663
+ export const toArray: <A>(r: Dictionary<A>) => ReadonlyArray<readonly [string, A]> = collect(tuple)
664
+
665
+ /**
666
+ * Converts an array of [key, value] into a record
667
+ */
668
+ export const fromArray = <V>(_: ReadonlyArray<readonly [string, V]>): Dictionary<V> =>
669
+ pipe(_, A.reduce({} as Dictionary<V>, (b, [k, v]) => Object.assign(b, { [k]: v })))