fortepiano 0.1.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 (94) hide show
  1. package/README.md +3 -0
  2. package/lib/Aggregate.d.ts +4 -0
  3. package/lib/Aggregate.js +2 -0
  4. package/lib/Binary.d.ts +5 -0
  5. package/lib/Binary.js +15 -0
  6. package/lib/Buffer.d.ts +5 -0
  7. package/lib/Buffer.js +45 -0
  8. package/lib/Cache.d.ts +18 -0
  9. package/lib/Cache.js +50 -0
  10. package/lib/Console.d.ts +20 -0
  11. package/lib/Console.js +25 -0
  12. package/lib/Crypto.d.ts +5 -0
  13. package/lib/Crypto.js +39 -0
  14. package/lib/Date.d.ts +4 -0
  15. package/lib/Date.js +30 -0
  16. package/lib/Eq.d.ts +4 -0
  17. package/lib/Eq.js +29 -0
  18. package/lib/Error.d.ts +6 -0
  19. package/lib/Error.js +56 -0
  20. package/lib/GeneratorL.d.ts +208 -0
  21. package/lib/GeneratorL.js +501 -0
  22. package/lib/Http.d.ts +60 -0
  23. package/lib/Http.js +131 -0
  24. package/lib/IOAsyncGenerator.d.ts +102 -0
  25. package/lib/IOAsyncGenerator.js +456 -0
  26. package/lib/Log.d.ts +4 -0
  27. package/lib/Log.js +5 -0
  28. package/lib/Magma.d.ts +2 -0
  29. package/lib/Magma.js +26 -0
  30. package/lib/Matrix.d.ts +9 -0
  31. package/lib/Matrix.js +36 -0
  32. package/lib/Mock.d.ts +76 -0
  33. package/lib/Mock.js +113 -0
  34. package/lib/Option.d.ts +2 -0
  35. package/lib/Option.js +26 -0
  36. package/lib/Random.d.ts +7 -0
  37. package/lib/Random.js +7 -0
  38. package/lib/Reader.d.ts +4 -0
  39. package/lib/Reader.js +31 -0
  40. package/lib/ReaderEither.d.ts +9 -0
  41. package/lib/ReaderEither.js +34 -0
  42. package/lib/ReaderTask.d.ts +8 -0
  43. package/lib/ReaderTask.js +35 -0
  44. package/lib/ReaderTaskEither.d.ts +17 -0
  45. package/lib/ReaderTaskEither.js +42 -0
  46. package/lib/ReadonlyArray.d.ts +75 -0
  47. package/lib/ReadonlyArray.js +70 -0
  48. package/lib/ReadonlyRecord.d.ts +4 -0
  49. package/lib/ReadonlyRecord.js +28 -0
  50. package/lib/ReadonlyTuple.d.ts +14 -0
  51. package/lib/ReadonlyTuple.js +34 -0
  52. package/lib/Storage.d.ts +15 -0
  53. package/lib/Storage.js +57 -0
  54. package/lib/Stream.d.ts +5 -0
  55. package/lib/Stream.js +31 -0
  56. package/lib/TaskEither.d.ts +2 -0
  57. package/lib/TaskEither.js +32 -0
  58. package/lib/Type.d.ts +11 -0
  59. package/lib/Type.js +53 -0
  60. package/lib/Validation.d.ts +4 -0
  61. package/lib/Validation.js +30 -0
  62. package/lib/cache/Memcached.d.ts +4 -0
  63. package/lib/cache/Memcached.js +50 -0
  64. package/lib/cache/Memory.d.ts +2 -0
  65. package/lib/cache/Memory.js +66 -0
  66. package/lib/cache/Redis.d.ts +4 -0
  67. package/lib/cache/Redis.js +58 -0
  68. package/lib/cache/Storage.d.ts +4 -0
  69. package/lib/cache/Storage.js +62 -0
  70. package/lib/function.d.ts +52 -0
  71. package/lib/function.js +101 -0
  72. package/lib/http/Axios.d.ts +3 -0
  73. package/lib/http/Axios.js +59 -0
  74. package/lib/http/Fetch.d.ts +2 -0
  75. package/lib/http/Fetch.js +71 -0
  76. package/lib/http/Got.d.ts +3 -0
  77. package/lib/http/Got.js +60 -0
  78. package/lib/http/Mock.d.ts +2 -0
  79. package/lib/http/Mock.js +52 -0
  80. package/lib/index.d.ts +48 -0
  81. package/lib/index.js +86 -0
  82. package/lib/log/Void.d.ts +3 -0
  83. package/lib/log/Void.js +6 -0
  84. package/lib/number.d.ts +3 -0
  85. package/lib/number.js +8 -0
  86. package/lib/storage/Flydrive.d.ts +4 -0
  87. package/lib/storage/Flydrive.js +67 -0
  88. package/lib/storage/Fs.d.ts +3 -0
  89. package/lib/storage/Fs.js +53 -0
  90. package/lib/string.d.ts +5 -0
  91. package/lib/string.js +33 -0
  92. package/lib/struct.d.ts +9 -0
  93. package/lib/struct.js +47 -0
  94. package/package.json +87 -0
@@ -0,0 +1,501 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.filterWithIndex = exports.FilterableWithIndex = exports.partitionMap = exports.partition = exports.filterMap = exports.filter = exports.Filterable = exports.separate = exports.compact = exports.Compactable = exports.duplicate = exports.extend = exports.Extend = exports.zero = exports.Alternative = exports.alt = exports.Alt = exports.unfold = exports.Unfoldable = exports.MonadIO = exports.chainFirstIOK = exports.chainIOK = exports.fromIOK = exports.fromIO = exports.FromIO = exports.Monad = exports.chainWithIndex = exports.bind = exports.chainFirst = exports.chain = exports.Chain = exports.Applicative = exports.apS = exports.apSecond = exports.apFirst = exports.ap = exports.Apply = exports.mapWithIndex = exports.FunctorWithIndex = exports.Do = exports.of = exports.Pointed = exports.bindTo = exports.flap = exports.map = exports.Functor = exports.getOrd = exports.getEq = exports.getMonoid = exports.URI = void 0;
23
+ exports.zip = exports.zipWith = exports.reverse = exports.sortBy = exports.sort = exports.uniq = exports.sieve = exports.scanRight = exports.scanLeft = exports.dropLeftWhile = exports.dropRight = exports.dropLeft = exports.takeLeftWhile = exports.takeRight = exports.takeLeft = exports.append = exports.prepend = exports.flatten = exports.fibonacci = exports.exp = exports.prime = exports.randomElem = exports.randomBool = exports.randomRange = exports.randomInt = exports.random = exports.fromReadonlyRecord = exports.fromReadonlyArray = exports.replicate = exports.range = exports.makeBy = exports.wither = exports.wilt = exports.Witherable = exports.traverseWithIndex = exports.TraversableWithIndex = exports.traverse = exports.Traversable = exports.sequence = exports.reduceRightWithIndex = exports.foldMapWithIndex = exports.reduceWithIndex = exports.FoldableWithIndex = exports.reduceRight = exports.foldMap = exports.reduce = exports.Foldable = exports.partitionMapWithIndex = exports.partitionWithIndex = exports.filterMapWithIndex = void 0;
24
+ exports.deleteAt = exports.updateAt = exports.modifyAt = exports.insertAt = exports.elem = exports.findLastIndex = exports.findLastMap = exports.findLast = exports.findFirstIndex = exports.findFirstMap = exports.findFirst = exports.isOutOfBound = exports.size = exports.isNonEmpty = exports.isEmpty = exports.unzip = exports.splitAt = exports.spanLeft = exports.init = exports.tail = exports.last = exports.head = exports.lookup = exports.toReadonlyArray = exports.matchRight = exports.matchLeft = exports.chunksOf = exports.chop = exports.rotate = exports.intersperse = exports.prependAll = exports.lefts = exports.rights = void 0;
25
+ const _Apply = __importStar(require("fp-ts/Apply"));
26
+ const Ch = __importStar(require("fp-ts/Chain"));
27
+ const Ei = __importStar(require("fp-ts/Either"));
28
+ const Eq = __importStar(require("fp-ts/Eq"));
29
+ const FIO = __importStar(require("fp-ts/FromIO"));
30
+ const function_1 = require("fp-ts/function");
31
+ const Fu = __importStar(require("fp-ts/Functor"));
32
+ const Op = __importStar(require("fp-ts/Option"));
33
+ const Or = __importStar(require("fp-ts/Ord"));
34
+ const R = __importStar(require("fp-ts/Random"));
35
+ const RA = __importStar(require("fp-ts/ReadonlyArray"));
36
+ const RR = __importStar(require("fp-ts/ReadonlyRecord"));
37
+ const S = __importStar(require("fp-ts/Separated"));
38
+ const function_2 = require("./function");
39
+ exports.URI = 'GeneratorL';
40
+ const getMonoid = () => ({
41
+ empty: exports.fromReadonlyArray([]),
42
+ concat: (x, y) => function* () {
43
+ yield* x();
44
+ yield* y();
45
+ },
46
+ });
47
+ exports.getMonoid = getMonoid;
48
+ const getEq = (E) => Eq.fromEquals((x, y) => {
49
+ const bs = y();
50
+ for (const a of x()) {
51
+ const b = bs.next();
52
+ if (b.done || !E.equals(a, b.value)) {
53
+ return false;
54
+ }
55
+ }
56
+ return Boolean(bs.next().done);
57
+ });
58
+ exports.getEq = getEq;
59
+ const getOrd = (O) => Or.fromCompare((first, second) => {
60
+ const bs = second();
61
+ for (const a of first()) {
62
+ const b = bs.next();
63
+ if (b.done) {
64
+ return 1;
65
+ }
66
+ const ordering = O.compare(a, b.value);
67
+ if (0 !== ordering) {
68
+ return ordering;
69
+ }
70
+ }
71
+ return !bs.next().done ? -1 : 0;
72
+ });
73
+ exports.getOrd = getOrd;
74
+ exports.Functor = {
75
+ URI: exports.URI,
76
+ map: (fa, f) => function* () {
77
+ for (const a of fa()) {
78
+ yield f(a);
79
+ }
80
+ },
81
+ };
82
+ exports.map = function_2.curry(function_1.flip(exports.Functor.map));
83
+ exports.flap = Fu.flap(exports.Functor);
84
+ exports.bindTo = Fu.bindTo(exports.Functor);
85
+ exports.Pointed = {
86
+ URI: exports.URI,
87
+ of: (a) => function* () {
88
+ yield a;
89
+ },
90
+ };
91
+ exports.of = exports.Pointed.of;
92
+ exports.Do = exports.Pointed.of({});
93
+ exports.FunctorWithIndex = Object.assign(Object.assign({}, exports.Functor), { mapWithIndex: (fa, f) => exports.Functor.map(function_1.pipe(fa, exports.zip(exports.range(0))), ([a, i]) => f(i, a)) });
94
+ exports.mapWithIndex = function_2.curry(function_1.flip(exports.FunctorWithIndex.mapWithIndex));
95
+ exports.Apply = Object.assign(Object.assign({}, exports.Functor), { ap: (fab, fa) => exports.Chain.chain(fab, function_2.curry(exports.Functor.map)(fa)) });
96
+ exports.ap = function_2.curry(function_1.flip(exports.Apply.ap));
97
+ exports.apFirst = _Apply.apFirst(exports.Apply);
98
+ exports.apSecond = _Apply.apSecond(exports.Apply);
99
+ exports.apS = _Apply.apS(exports.Apply);
100
+ exports.Applicative = Object.assign(Object.assign({}, exports.Pointed), exports.Apply);
101
+ exports.Chain = Object.assign(Object.assign({}, exports.Apply), { chain: (fa, f) => exports.flatten(exports.Functor.map(fa, f)) });
102
+ exports.chain = function_2.curry(function_1.flip(exports.Chain.chain));
103
+ exports.chainFirst = Ch.chainFirst(exports.Chain);
104
+ exports.bind = Ch.bind(exports.Chain);
105
+ const chainWithIndex = (f) => (fa) => function_1.pipe(fa, exports.zip(exports.range(0)), exports.chain(([a, i]) => f(i, a)));
106
+ exports.chainWithIndex = chainWithIndex;
107
+ exports.Monad = Object.assign(Object.assign({}, exports.Applicative), exports.Chain);
108
+ exports.FromIO = {
109
+ URI: exports.URI,
110
+ fromIO: (fa) => function_1.pipe(exports.range(0), exports.map(fa)),
111
+ };
112
+ exports.fromIO = exports.FromIO.fromIO;
113
+ exports.fromIOK = FIO.fromIOK(exports.FromIO);
114
+ exports.chainIOK = FIO.chainIOK(exports.FromIO, exports.Chain);
115
+ exports.chainFirstIOK = FIO.chainFirstIOK(exports.FromIO, exports.Chain);
116
+ exports.MonadIO = Object.assign(Object.assign({}, exports.Monad), exports.FromIO);
117
+ exports.Unfoldable = {
118
+ URI: exports.URI,
119
+ unfold: (b, f) => function* () {
120
+ for (let _b = b, ab = f(_b); Op.isSome(ab); _b = ab.value[1], ab = f(_b)) {
121
+ yield ab.value[0];
122
+ }
123
+ },
124
+ };
125
+ exports.unfold = function_2.curry(function_1.flip(exports.Unfoldable.unfold));
126
+ exports.Alt = Object.assign(Object.assign({}, exports.Functor), { alt: (fa, that) => exports.getMonoid().concat(fa, that()) });
127
+ exports.alt = function_2.curry(function_1.flip(exports.Alt.alt));
128
+ exports.Alternative = Object.assign(Object.assign(Object.assign({}, exports.Applicative), exports.Alt), { zero: () => exports.getMonoid().empty });
129
+ exports.zero = exports.Alternative.zero;
130
+ exports.Extend = Object.assign(Object.assign({}, exports.Functor), { extend: (wa, f) => function_1.pipe(wa, exports.mapWithIndex((i) => function_1.pipe(wa, exports.dropLeft(i), f))) });
131
+ exports.extend = function_2.curry(function_1.flip(exports.Extend.extend));
132
+ const duplicate = (fa) => function_1.pipe(fa, exports.extend(function_1.identity));
133
+ exports.duplicate = duplicate;
134
+ exports.Compactable = {
135
+ URI: exports.URI,
136
+ compact: (fa) => exports.Functor.map(exports.Filterable.filter(fa, Op.isSome), (a) => a.value),
137
+ separate: (fa) => S.separated(exports.Functor.map(exports.Filterable.filter(fa, Ei.isLeft), (a) => a.left), exports.Functor.map(exports.Filterable.filter(fa, Ei.isRight), (a) => a.right)),
138
+ };
139
+ exports.compact = exports.Compactable.compact;
140
+ exports.separate = exports.Compactable.separate;
141
+ function _filter(fa, predicate) {
142
+ return function* () {
143
+ for (const a of fa()) {
144
+ if (!predicate(a)) {
145
+ continue;
146
+ }
147
+ yield a;
148
+ }
149
+ };
150
+ }
151
+ function _partition(fa, predicate) {
152
+ return S.separated(exports.Filterable.filter(fa, function_1.not(predicate)), exports.Filterable.filter(fa, predicate));
153
+ }
154
+ exports.Filterable = Object.assign(Object.assign(Object.assign({}, exports.Functor), exports.Compactable), { filter: _filter, filterMap: (fa, f) => exports.Compactable.compact(exports.Functor.map(fa, f)), partition: _partition, partitionMap: (fa, f) => exports.Compactable.separate(exports.Functor.map(fa, f)) });
155
+ function filter(predicate) {
156
+ return (fa) => exports.Filterable.filter(fa, predicate);
157
+ }
158
+ exports.filter = filter;
159
+ exports.filterMap = function_2.curry(function_1.flip(exports.Filterable.filterMap));
160
+ function partition(predicate) {
161
+ return (fa) => exports.Filterable.partition(fa, predicate);
162
+ }
163
+ exports.partition = partition;
164
+ exports.partitionMap = function_2.curry(function_1.flip(exports.Filterable.partitionMap));
165
+ function _filterWithIndex(fa, predicateWithIndex) {
166
+ return exports.Compactable.compact(exports.FunctorWithIndex.mapWithIndex(fa, (i, a) => predicateWithIndex(i, a) ? Op.some(a) : Op.none));
167
+ }
168
+ function _partitionWithIndex(fa, predicateWithIndex) {
169
+ return exports.Compactable.separate(exports.FunctorWithIndex.mapWithIndex(fa, (i, a) => predicateWithIndex(i, a) ? Ei.right(a) : Ei.left(a)));
170
+ }
171
+ exports.FilterableWithIndex = Object.assign(Object.assign(Object.assign({}, exports.FunctorWithIndex), exports.Filterable), { filterWithIndex: _filterWithIndex, filterMapWithIndex: (fa, f) => exports.Compactable.compact(exports.FunctorWithIndex.mapWithIndex(fa, f)), partitionWithIndex: _partitionWithIndex, partitionMapWithIndex: (fa, f) => exports.Compactable.separate(exports.FunctorWithIndex.mapWithIndex(fa, f)) });
172
+ function filterWithIndex(predicateWithIndex) {
173
+ return (fa) => exports.FilterableWithIndex.filterWithIndex(fa, predicateWithIndex);
174
+ }
175
+ exports.filterWithIndex = filterWithIndex;
176
+ exports.filterMapWithIndex = function_2.curry(function_1.flip(exports.FilterableWithIndex.filterMapWithIndex));
177
+ function partitionWithIndex(predicateWithIndex) {
178
+ return (fa) => exports.FilterableWithIndex.partitionWithIndex(fa, predicateWithIndex);
179
+ }
180
+ exports.partitionWithIndex = partitionWithIndex;
181
+ exports.partitionMapWithIndex = function_2.curry(function_1.flip(exports.FilterableWithIndex.partitionMapWithIndex));
182
+ exports.Foldable = {
183
+ URI: exports.URI,
184
+ reduce: (fa, b, f) => exports.FoldableWithIndex.reduceWithIndex(fa, b, (_, _b, a) => f(_b, a)),
185
+ foldMap: (M) => (fa, f) => exports.FoldableWithIndex.foldMapWithIndex(M)(fa, (_, a) => f(a)),
186
+ reduceRight: (fa, b, f) => exports.FoldableWithIndex.reduceRightWithIndex(fa, b, (_, a, _b) => f(a, _b)),
187
+ };
188
+ const reduce = (b, f) => (fa) => exports.Foldable.reduce(fa, b, f);
189
+ exports.reduce = reduce;
190
+ const foldMap = (M) => (f) => (fa) => exports.Foldable.foldMap(M)(fa, f);
191
+ exports.foldMap = foldMap;
192
+ const reduceRight = (b, f) => (fa) => exports.Foldable.reduceRight(fa, b, f);
193
+ exports.reduceRight = reduceRight;
194
+ exports.FoldableWithIndex = Object.assign(Object.assign({}, exports.Foldable), { reduceWithIndex: (fa, b, f) => function_1.pipe(fa, exports.zip(exports.range(0)), (_fa) => {
195
+ let _b = b;
196
+ for (const [a, i] of _fa()) {
197
+ _b = f(i, _b, a);
198
+ }
199
+ return _b;
200
+ }), foldMapWithIndex: (M) => (fa, f) => exports.FoldableWithIndex.reduceWithIndex(fa, M.empty, (i, b, a) => M.concat(b, f(i, a))), reduceRightWithIndex: (fa, b, f) => function_1.pipe(fa, exports.toReadonlyArray, RA.reduceRightWithIndex(b, f)) });
201
+ const reduceWithIndex = (b, f) => (fa) => exports.FoldableWithIndex.reduceWithIndex(fa, b, f);
202
+ exports.reduceWithIndex = reduceWithIndex;
203
+ const foldMapWithIndex = (M) => (f) => (fa) => exports.FoldableWithIndex.foldMapWithIndex(M)(fa, f);
204
+ exports.foldMapWithIndex = foldMapWithIndex;
205
+ const reduceRightWithIndex = (b, f) => (fa) => exports.FoldableWithIndex.reduceRightWithIndex(fa, b, f);
206
+ exports.reduceRightWithIndex = reduceRightWithIndex;
207
+ function _traverse(F) {
208
+ return (ta, f) => exports.TraversableWithIndex.traverseWithIndex(F)(ta, (_, a) => f(a));
209
+ }
210
+ function sequence(F) {
211
+ return (ta) => exports.Traversable.traverse(F)(ta, function_1.identity);
212
+ }
213
+ exports.sequence = sequence;
214
+ exports.Traversable = Object.assign(Object.assign(Object.assign({}, exports.Functor), exports.Foldable), { traverse: _traverse, sequence });
215
+ function traverse(F) {
216
+ return (f) => (ta) => exports.Traversable.traverse(F)(ta, f);
217
+ }
218
+ exports.traverse = traverse;
219
+ function _traverseWithIndex(F) {
220
+ return (ta, f) => exports.FoldableWithIndex.reduceWithIndex(ta, F.of(exports.zero()), (i, fbs, a) => F.ap(F.map(fbs, (bs) => (b) => function_1.pipe(bs, exports.append(b))), f(i, a)));
221
+ }
222
+ exports.TraversableWithIndex = Object.assign(Object.assign(Object.assign(Object.assign({}, exports.FunctorWithIndex), exports.FoldableWithIndex), exports.Traversable), { traverseWithIndex: _traverseWithIndex });
223
+ function traverseWithIndex(F) {
224
+ return (f) => (ta) => exports.TraversableWithIndex.traverseWithIndex(F)(ta, f);
225
+ }
226
+ exports.traverseWithIndex = traverseWithIndex;
227
+ function _wilt(F) {
228
+ return (wa, f) => F.map(exports.Traversable.traverse(F)(wa, f), exports.separate);
229
+ }
230
+ function _wither(F) {
231
+ return (ta, f) => F.map(exports.Traversable.traverse(F)(ta, f), exports.compact);
232
+ }
233
+ exports.Witherable = Object.assign(Object.assign(Object.assign({}, exports.Traversable), exports.Filterable), { wilt: _wilt, wither: _wither });
234
+ function wilt(F) {
235
+ return (f) => (wa) => exports.Witherable.wilt(F)(wa, f);
236
+ }
237
+ exports.wilt = wilt;
238
+ function wither(F) {
239
+ return (f) => (ta) => exports.Witherable.wither(F)(ta, f);
240
+ }
241
+ exports.wither = wither;
242
+ const makeBy = (f) => function* () {
243
+ for (let i = 0; true; i++) {
244
+ yield f(i);
245
+ }
246
+ };
247
+ exports.makeBy = makeBy;
248
+ const range = (start, end = Infinity) => function_1.pipe(exports.makeBy((i) => start + i), takeLeftWhile((n) => n <= Math.max(start, end)));
249
+ exports.range = range;
250
+ const replicate = (a) => exports.makeBy(() => a);
251
+ exports.replicate = replicate;
252
+ const fromReadonlyArray = (as) => function* () {
253
+ yield* as;
254
+ };
255
+ exports.fromReadonlyArray = fromReadonlyArray;
256
+ exports.fromReadonlyRecord = RR.toUnfoldable(exports.Unfoldable);
257
+ exports.random = exports.fromIO(R.random);
258
+ const randomInt = (low, high) => exports.fromIO(R.randomInt(Math.floor(low), Math.max(Math.floor(low), Math.floor(high))));
259
+ exports.randomInt = randomInt;
260
+ const randomRange = (min, max) => exports.fromIO(R.randomRange(min, Math.max(min, max)));
261
+ exports.randomRange = randomRange;
262
+ exports.randomBool = exports.fromIO(R.randomBool);
263
+ const randomElem = (as) => exports.fromIO(R.randomElem(as));
264
+ exports.randomElem = randomElem;
265
+ exports.prime = function_1.pipe(exports.range(2), sieve((init, n) => function_1.pipe(init, RA.every((_n) => 0 !== n % _n))));
266
+ exports.exp = exports.makeBy((n) => Math.exp(n));
267
+ const fibonacci = function* () {
268
+ for (let ns = [1, 0]; true; ns = [ns[1], ns[0] + ns[1]]) {
269
+ yield ns[1];
270
+ }
271
+ };
272
+ exports.fibonacci = fibonacci;
273
+ const flatten = (mma) => function* () {
274
+ for (const ma of mma()) {
275
+ yield* ma();
276
+ }
277
+ };
278
+ exports.flatten = flatten;
279
+ const prepend = (a) => (ma) => function* () {
280
+ yield a;
281
+ yield* ma();
282
+ };
283
+ exports.prepend = prepend;
284
+ const append = (a) => (ma) => function* () {
285
+ yield* ma();
286
+ yield a;
287
+ };
288
+ exports.append = append;
289
+ const takeLeft = (n) => (ma) => function* () {
290
+ for (const [a, i] of function_1.pipe(ma, exports.zip(exports.range(0)))()) {
291
+ if (i >= n) {
292
+ break;
293
+ }
294
+ yield a;
295
+ }
296
+ };
297
+ exports.takeLeft = takeLeft;
298
+ const takeRight = (n) => (ma) => function_1.pipe(ma, exports.toReadonlyArray, RA.takeRight(n), exports.fromReadonlyArray);
299
+ exports.takeRight = takeRight;
300
+ function takeLeftWhile(predicate) {
301
+ return (ma) => function* () {
302
+ for (const a of ma()) {
303
+ if (!predicate(a)) {
304
+ break;
305
+ }
306
+ yield a;
307
+ }
308
+ };
309
+ }
310
+ exports.takeLeftWhile = takeLeftWhile;
311
+ const dropLeft = (n) => (ma) => function* () {
312
+ for (const [a, i] of function_1.pipe(ma, exports.zip(exports.range(0)))()) {
313
+ if (i < n) {
314
+ continue;
315
+ }
316
+ yield a;
317
+ }
318
+ };
319
+ exports.dropLeft = dropLeft;
320
+ const dropRight = (n) => (ma) => function_1.pipe(ma, exports.toReadonlyArray, RA.dropRight(n), exports.fromReadonlyArray);
321
+ exports.dropRight = dropRight;
322
+ function dropLeftWhile(predicate) {
323
+ return (ma) => function* () {
324
+ const as = ma();
325
+ let a = as.next();
326
+ while (!a.done && predicate(a.value)) {
327
+ a = as.next();
328
+ }
329
+ if (!a.done) {
330
+ yield a.value;
331
+ }
332
+ yield* as;
333
+ };
334
+ }
335
+ exports.dropLeftWhile = dropLeftWhile;
336
+ const scanLeft = (b, f) => (ma) => function* () {
337
+ yield b;
338
+ let _b = b;
339
+ for (const a of ma()) {
340
+ _b = f(_b, a);
341
+ yield _b;
342
+ }
343
+ };
344
+ exports.scanLeft = scanLeft;
345
+ const scanRight = (b, f) => (ma) => function_1.pipe(ma, exports.scanLeft(b, (b, a) => f(a, b)), exports.reverse);
346
+ exports.scanRight = scanRight;
347
+ function sieve(f) {
348
+ return (ma) => function* () {
349
+ const init = [];
350
+ for (const a of ma()) {
351
+ if (!f(init, a)) {
352
+ continue;
353
+ }
354
+ init.push(a);
355
+ yield a;
356
+ }
357
+ };
358
+ }
359
+ exports.sieve = sieve;
360
+ const uniq = (E) => sieve((init, a) => !function_1.pipe(init, RA.elem(E)(a)));
361
+ exports.uniq = uniq;
362
+ const sort = (O) => exports.sortBy([O]);
363
+ exports.sort = sort;
364
+ const sortBy = (Os) => (ma) => function_1.pipe(ma, exports.toReadonlyArray, RA.sortBy(Os), exports.fromReadonlyArray);
365
+ exports.sortBy = sortBy;
366
+ const reverse = (ma) => function* () {
367
+ const as = exports.toReadonlyArray(ma);
368
+ for (let i = as.length - 1; i >= 0; i--) {
369
+ yield as[i];
370
+ }
371
+ };
372
+ exports.reverse = reverse;
373
+ const zipWith = (mb, f) => (ma) => function* () {
374
+ const bs = mb();
375
+ for (const a of ma()) {
376
+ const b = bs.next();
377
+ if (b.done) {
378
+ break;
379
+ }
380
+ yield f(a, b.value);
381
+ }
382
+ };
383
+ exports.zipWith = zipWith;
384
+ const zip = (mb) => (ma) => function_1.pipe(ma, exports.zipWith(mb, (a, b) => [a, b]));
385
+ exports.zip = zip;
386
+ const rights = (ma) => function_1.pipe(ma, exports.filterMap(Op.fromEither));
387
+ exports.rights = rights;
388
+ const lefts = (ma) => function_1.pipe(ma, filter(Ei.isLeft), exports.map((e) => e.left));
389
+ exports.lefts = lefts;
390
+ const prependAll = (middle) => (ma) => function_1.pipe(ma, exports.matchLeft(() => ma, () => function* () {
391
+ for (const a of ma()) {
392
+ yield middle;
393
+ yield a;
394
+ }
395
+ }));
396
+ exports.prependAll = prependAll;
397
+ const intersperse = (middle) => function_1.flow(exports.prependAll(middle), exports.dropLeft(1));
398
+ exports.intersperse = intersperse;
399
+ const rotate = (n) => (ma) => function_1.pipe(ma, exports.toReadonlyArray, RA.rotate(n), exports.fromReadonlyArray);
400
+ exports.rotate = rotate;
401
+ const chop = (f) => (ma) => function* () {
402
+ for (let _isNonEmpty = exports.isNonEmpty(ma), [b, _ma] = f(ma); _isNonEmpty; _isNonEmpty = exports.isNonEmpty(_ma), [b, _ma] = f(_ma)) {
403
+ yield b;
404
+ }
405
+ };
406
+ exports.chop = chop;
407
+ const chunksOf = (n) => (ma) => function_1.pipe(ma, exports.chop(exports.splitAt(Math.max(1, n))));
408
+ exports.chunksOf = chunksOf;
409
+ const matchLeft = (onEmpty, onNonEmpty) => (ma) => function_1.pipe(ma().next(), (a) => a.done ? onEmpty() : onNonEmpty(a.value, function_1.pipe(ma, exports.dropLeft(1))));
410
+ exports.matchLeft = matchLeft;
411
+ const matchRight = (onEmpty, onNonEmpty) => (ma) => function_1.pipe(ma, exports.zip(exports.range(0)), exports.last, Op.match(onEmpty, ([a, i]) => onNonEmpty(function_1.pipe(ma, filterWithIndex((_i) => i !== _i)), a)));
412
+ exports.matchRight = matchRight;
413
+ const toReadonlyArray = (ma) => [
414
+ ...ma(),
415
+ ];
416
+ exports.toReadonlyArray = toReadonlyArray;
417
+ const lookup = (i) => (ma) => i < 0
418
+ ? Op.none
419
+ : function_1.pipe(ma, exports.dropLeft(i), exports.matchLeft(() => Op.none, Op.some));
420
+ exports.lookup = lookup;
421
+ exports.head = exports.lookup(0);
422
+ const last = (ma) => {
423
+ let last = Op.none;
424
+ for (const a of ma()) {
425
+ last = Op.some(a);
426
+ }
427
+ return last;
428
+ };
429
+ exports.last = last;
430
+ const tail = (ma) => function_1.pipe(ma, exports.matchLeft(() => Op.none, (_, tail) => Op.some(tail)));
431
+ exports.tail = tail;
432
+ const init = (ma) => function_1.pipe(ma, exports.matchRight(() => Op.none, Op.some));
433
+ exports.init = init;
434
+ function spanLeft(predicate) {
435
+ return (ma) => {
436
+ const i = function_1.pipe(ma, exports.findFirstIndex(function_1.not(predicate)), Op.getOrElse(() => Infinity));
437
+ const [init, rest] = function_1.pipe(ma, exports.splitAt(i));
438
+ return { init, rest };
439
+ };
440
+ }
441
+ exports.spanLeft = spanLeft;
442
+ const splitAt = (n) => (ma) => [function_1.pipe(ma, exports.takeLeft(n)), function_1.pipe(ma, exports.dropLeft(n))];
443
+ exports.splitAt = splitAt;
444
+ const unzip = (mab) => [
445
+ function_1.pipe(mab, exports.map(([a]) => a)),
446
+ function_1.pipe(mab, exports.map(([_, b]) => b)),
447
+ ];
448
+ exports.unzip = unzip;
449
+ exports.isEmpty = exports.matchLeft(function_1.constTrue, function_1.constFalse);
450
+ exports.isNonEmpty = function_1.not(exports.isEmpty);
451
+ exports.size = function_1.flow(exports.mapWithIndex(function_1.identity), exports.last, Op.match(() => 0, (i) => 1 + i));
452
+ const isOutOfBound = (n) => (ma) => n >= 0 && n < exports.size(ma);
453
+ exports.isOutOfBound = isOutOfBound;
454
+ function findFirst(predicate) {
455
+ return (ma) => {
456
+ for (const a of ma()) {
457
+ if (predicate(a)) {
458
+ return Op.some(a);
459
+ }
460
+ }
461
+ return Op.none;
462
+ };
463
+ }
464
+ exports.findFirst = findFirst;
465
+ const findFirstMap = (f) => (ma) => {
466
+ for (const a of ma()) {
467
+ const b = f(a);
468
+ if (Op.isSome(b)) {
469
+ return b;
470
+ }
471
+ }
472
+ return Op.none;
473
+ };
474
+ exports.findFirstMap = findFirstMap;
475
+ const findFirstIndex = (predicate) => (ma) => function_1.pipe(ma, exports.zip(exports.range(0)), findFirst(([a]) => predicate(a)), Op.map(([_, i]) => i));
476
+ exports.findFirstIndex = findFirstIndex;
477
+ function findLast(predicate) {
478
+ return (ma) => function_1.pipe(ma, exports.reverse, findFirst(predicate));
479
+ }
480
+ exports.findLast = findLast;
481
+ const findLastMap = (f) => (ma) => function_1.pipe(ma, exports.reverse, exports.findFirstMap(f));
482
+ exports.findLastMap = findLastMap;
483
+ const findLastIndex = (predicate) => (ma) => function_1.pipe(ma, exports.zip(exports.range(0)), exports.findLastMap(([a, i]) => (predicate(a) ? Op.some(i) : Op.none)));
484
+ exports.findLastIndex = findLastIndex;
485
+ const elem = (Eq) => (a) => findFirst((_a) => Eq.equals(a, _a));
486
+ exports.elem = elem;
487
+ const insertAt = (i, a) => (ma) => function_1.pipe(ma, exports.lookup(i), Op.map(() => function* () {
488
+ for (const [_a, _i] of function_1.pipe(ma, exports.zip(exports.range(0)))()) {
489
+ if (i === _i) {
490
+ yield a;
491
+ }
492
+ yield _a;
493
+ }
494
+ }));
495
+ exports.insertAt = insertAt;
496
+ const modifyAt = (i, f) => (ma) => function_1.pipe(ma, exports.lookup(i), Op.map(() => function_1.pipe(ma, exports.mapWithIndex((_i, a) => (i === _i ? f(a) : a)))));
497
+ exports.modifyAt = modifyAt;
498
+ const updateAt = (i, a) => exports.modifyAt(i, () => a);
499
+ exports.updateAt = updateAt;
500
+ const deleteAt = (i) => (ma) => function_1.pipe(ma, exports.lookup(i), Op.map(() => function_1.pipe(ma, filterWithIndex((_i) => i !== _i))));
501
+ exports.deleteAt = deleteAt;
package/lib/Http.d.ts ADDED
@@ -0,0 +1,60 @@
1
+ /// <reference types="node" />
2
+ import * as RR from 'fp-ts/ReadonlyRecord';
3
+ import * as TE from 'fp-ts/TaskEither';
4
+ import * as t from 'io-ts';
5
+ import * as $C from './Cache';
6
+ import { mock } from './http/Mock';
7
+ import * as $L from './Log';
8
+ import * as $Stru from './struct';
9
+ export interface Http {
10
+ readonly delete: HttpRequest<'body'>;
11
+ readonly get: HttpRequest<'body'>;
12
+ readonly patch: HttpRequest;
13
+ readonly post: HttpRequest;
14
+ readonly put: HttpRequest;
15
+ readonly head: HttpRequest<'body'>;
16
+ readonly options: HttpRequest<'body'>;
17
+ }
18
+ export interface HttpResponse<A = unknown> {
19
+ readonly url: string;
20
+ readonly status: number;
21
+ readonly headers: RR.ReadonlyRecord<string, string | ReadonlyArray<string>>;
22
+ readonly body: A;
23
+ }
24
+ export declare class HttpError extends Error {
25
+ readonly response: HttpResponse;
26
+ constructor(response: HttpResponse, message?: string);
27
+ }
28
+ export interface HttpOptions {
29
+ readonly body?: $Stru.struct | Buffer;
30
+ readonly headers?: RR.ReadonlyRecord<string, string>;
31
+ readonly json?: boolean;
32
+ readonly buffer?: boolean;
33
+ readonly query?: RR.ReadonlyRecord<string, boolean | number | string>;
34
+ }
35
+ export interface HttpRequest<A extends keyof HttpOptions = never> {
36
+ (url: string, options?: Omit<HttpOptions, A>): TE.TaskEither<Error | HttpError, HttpResponse>;
37
+ }
38
+ export declare const HttpMethodC: t.KeyofC<{
39
+ readonly get: null;
40
+ readonly delete: null;
41
+ readonly head: null;
42
+ readonly options: null;
43
+ readonly patch: null;
44
+ readonly post: null;
45
+ readonly put: null;
46
+ }>;
47
+ export declare type HttpMethod = t.TypeOf<typeof HttpMethodC>;
48
+ export declare const HttpResponseC: <C extends t.Mixed>(codec: C) => t.TypeC<{
49
+ url: t.StringC;
50
+ status: t.NumberC;
51
+ headers: t.ReadonlyC<t.RecordC<t.StringC, t.UnionC<[t.StringC, t.ReadonlyArrayC<t.StringC>]>>>;
52
+ body: C;
53
+ }>;
54
+ export declare const HttpErrorC: <A extends "BadRequest" | "Unauthorized" | "Forbidden" | "NotFound" | "UnprocessableEntity">(type?: A | undefined) => t.Type<HttpError, HttpError, unknown>;
55
+ export declare const json: (http: Http) => Http;
56
+ export declare const buffer: (http: Http) => Http;
57
+ export declare const cache: (cache: $C.Cache) => (http: Http) => Http;
58
+ export declare const pool: (http: Http) => Http;
59
+ export declare const log: (logStart: $L.Logger, logEnd?: $L.Logger) => (http: Http) => Http;
60
+ export { mock };