functionalscript 0.2.0 → 0.2.1

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 (248) hide show
  1. package/dev/module.mjs +1 -1
  2. package/jsr.json +59 -59
  3. package/out/com/cpp/module.f.mjs +123 -0
  4. package/out/com/cpp/test.f.mjs +40 -0
  5. package/out/com/cpp/testlib.f.mjs +7 -0
  6. package/out/com/cs/module.f.mjs +95 -0
  7. package/out/com/cs/test.f.mjs +43 -0
  8. package/out/com/cs/testlib.f.mjs +7 -0
  9. package/out/com/rust/module.f.mjs +213 -0
  10. package/out/com/rust/test.f.mjs +123 -0
  11. package/out/com/rust/testlib.f.mjs +7 -0
  12. package/out/com/test/build.f.mjs +98 -0
  13. package/out/com/test/build.mjs +40 -0
  14. package/out/com/types/module.f.mjs +51 -0
  15. package/out/com/types/testlib.f.mjs +30 -0
  16. package/out/commonjs/build/module.f.mjs +107 -0
  17. package/out/commonjs/build/test.f.mjs +102 -0
  18. package/out/commonjs/module/function/module.f.mjs +15 -0
  19. package/out/commonjs/module/module.f.mjs +48 -0
  20. package/out/commonjs/module.f.mjs +10 -0
  21. package/out/commonjs/module.mjs +26 -0
  22. package/out/commonjs/package/dependencies/module.f.mjs +21 -0
  23. package/out/commonjs/package/dependencies/test.f.mjs +15 -0
  24. package/out/commonjs/package/module.f.mjs +40 -0
  25. package/out/commonjs/package/test.f.mjs +27 -0
  26. package/out/commonjs/path/module.f.mjs +171 -0
  27. package/out/commonjs/path/test.f.mjs +231 -0
  28. package/out/commonjs/test.mjs +87 -0
  29. package/out/dev/index.mjs +2 -0
  30. package/out/dev/module.f.mjs +2 -0
  31. package/out/dev/module.mjs +167 -0
  32. package/out/dev/test/module.f.mjs +134 -0
  33. package/out/dev/test.f.mjs +58 -0
  34. package/out/dev/test.mjs +52 -0
  35. package/out/djs/module.f.mjs +75 -0
  36. package/out/djs/parser/module.f.mjs +432 -0
  37. package/out/djs/parser/test.f.mjs +535 -0
  38. package/out/djs/test.f.mjs +84 -0
  39. package/out/djs/tokenizer/module.f.mjs +87 -0
  40. package/out/djs/tokenizer/test.f.mjs +480 -0
  41. package/out/fsc/module.f.mjs +105 -0
  42. package/out/fsc/test.f.mjs +19 -0
  43. package/out/fsm/module.f.mjs +80 -0
  44. package/out/fsm/test.f.mjs +138 -0
  45. package/out/html/module.f.mjs +94 -0
  46. package/out/html/test.f.mjs +45 -0
  47. package/out/issues/test.f.mjs +66 -0
  48. package/out/js/tokenizer/module.f.mjs +686 -0
  49. package/out/js/tokenizer/test.f.mjs +844 -0
  50. package/out/json/module.f.mjs +89 -0
  51. package/out/json/parser/module.f.mjs +224 -0
  52. package/out/json/parser/test.f.mjs +321 -0
  53. package/out/json/serializer/module.f.mjs +67 -0
  54. package/out/json/serializer/test.f.mjs +87 -0
  55. package/out/json/test.f.mjs +61 -0
  56. package/out/json/tokenizer/module.f.mjs +78 -0
  57. package/out/json/tokenizer/test.f.mjs +420 -0
  58. package/out/nanvm-lib/tests/test.f.mjs +87 -0
  59. package/out/nodejs/version/main.mjs +3 -0
  60. package/out/nodejs/version/module.f.mjs +34 -0
  61. package/out/nodejs/version/test.f.mjs +97 -0
  62. package/out/prime_field/module.f.mjs +87 -0
  63. package/out/prime_field/test.f.mjs +145 -0
  64. package/out/secp/module.f.mjs +113 -0
  65. package/out/secp/test.f.mjs +63 -0
  66. package/out/sha2/module.f.mjs +172 -0
  67. package/out/sha2/test.f.mjs +86 -0
  68. package/out/text/ascii/module.f.mjs +154 -0
  69. package/out/text/ascii/test.f.mjs +14 -0
  70. package/out/text/module.f.mjs +19 -0
  71. package/out/text/sgr/module.f.mjs +17 -0
  72. package/out/text/test.f.mjs +19 -0
  73. package/out/text/utf16/module.f.mjs +86 -0
  74. package/out/text/utf16/test.f.mjs +145 -0
  75. package/out/text/utf8/module.f.mjs +126 -0
  76. package/out/text/utf8/test.f.mjs +175 -0
  77. package/out/types/array/module.f.mjs +95 -0
  78. package/out/types/array/test.f.mjs +116 -0
  79. package/out/types/bigfloat/module.f.mjs +77 -0
  80. package/out/types/bigfloat/test.f.mjs +349 -0
  81. package/out/types/bigint/module.f.mjs +114 -0
  82. package/out/types/bigint/test.f.mjs +192 -0
  83. package/out/types/btree/find/module.f.mjs +137 -0
  84. package/out/types/btree/find/test.f.mjs +156 -0
  85. package/out/types/btree/module.f.mjs +34 -0
  86. package/out/types/btree/remove/module.f.mjs +209 -0
  87. package/out/types/btree/remove/test.f.mjs +638 -0
  88. package/out/types/btree/set/module.f.mjs +114 -0
  89. package/out/types/btree/set/test.f.mjs +390 -0
  90. package/out/types/btree/test.f.mjs +83 -0
  91. package/out/types/btree/types/module.f.mjs +50 -0
  92. package/out/types/byte_set/module.f.mjs +42 -0
  93. package/out/types/byte_set/test.f.mjs +123 -0
  94. package/out/types/function/compare/module.f.mjs +22 -0
  95. package/out/types/function/compare/test.f.mjs +8 -0
  96. package/out/types/function/module.f.mjs +44 -0
  97. package/out/types/function/operator/module.f.mjs +60 -0
  98. package/out/types/function/test.f.mjs +15 -0
  99. package/out/types/list/module.f.mjs +269 -0
  100. package/out/types/list/test.f.mjs +401 -0
  101. package/out/types/map/module.f.mjs +54 -0
  102. package/out/types/map/test.f.mjs +115 -0
  103. package/out/types/nibble_set/module.f.mjs +19 -0
  104. package/out/types/nibble_set/test.f.mjs +90 -0
  105. package/out/types/nullable/module.f.mjs +9 -0
  106. package/out/types/nullable/test.f.mjs +12 -0
  107. package/out/types/number/module.f.mjs +12 -0
  108. package/out/types/number/test.f.mjs +126 -0
  109. package/out/types/object/module.f.mjs +27 -0
  110. package/out/types/object/test.f.mjs +17 -0
  111. package/out/types/range/module.f.mjs +6 -0
  112. package/out/types/range/test.f.mjs +18 -0
  113. package/out/types/range_map/module.f.mjs +84 -0
  114. package/out/types/range_map/test.f.mjs +201 -0
  115. package/out/types/result/module.f.mjs +25 -0
  116. package/out/types/result/module.mjs +16 -0
  117. package/out/types/sorted_list/module.f.mjs +102 -0
  118. package/out/types/sorted_list/test.f.mjs +66 -0
  119. package/out/types/sorted_set/module.f.mjs +29 -0
  120. package/out/types/sorted_set/test.f.mjs +80 -0
  121. package/out/types/string/module.f.mjs +17 -0
  122. package/out/types/string/test.f.mjs +58 -0
  123. package/out/types/string_set/module.f.mjs +29 -0
  124. package/out/types/string_set/test.f.mjs +65 -0
  125. package/package.json +5 -4
  126. package/tsconfig.json +2 -2
  127. /package/{com → out/com}/cpp/module.f.d.mts +0 -0
  128. /package/{com → out/com}/cpp/test.f.d.mts +0 -0
  129. /package/{com → out/com}/cpp/testlib.f.d.mts +0 -0
  130. /package/{com → out/com}/cs/module.f.d.mts +0 -0
  131. /package/{com → out/com}/cs/test.f.d.mts +0 -0
  132. /package/{com → out/com}/cs/testlib.f.d.mts +0 -0
  133. /package/{com → out/com}/rust/module.f.d.mts +0 -0
  134. /package/{com → out/com}/rust/test.f.d.mts +0 -0
  135. /package/{com → out/com}/rust/testlib.f.d.mts +0 -0
  136. /package/{com → out/com}/test/build.d.mts +0 -0
  137. /package/{com → out/com}/test/build.f.d.mts +0 -0
  138. /package/{com → out/com}/types/module.f.d.mts +0 -0
  139. /package/{com → out/com}/types/testlib.f.d.mts +0 -0
  140. /package/{commonjs → out/commonjs}/build/module.f.d.mts +0 -0
  141. /package/{commonjs → out/commonjs}/build/test.f.d.mts +0 -0
  142. /package/{commonjs → out/commonjs}/module/function/module.f.d.mts +0 -0
  143. /package/{commonjs → out/commonjs}/module/module.f.d.mts +0 -0
  144. /package/{commonjs → out/commonjs}/module.d.mts +0 -0
  145. /package/{commonjs → out/commonjs}/module.f.d.mts +0 -0
  146. /package/{commonjs → out/commonjs}/package/dependencies/module.f.d.mts +0 -0
  147. /package/{commonjs → out/commonjs}/package/dependencies/test.f.d.mts +0 -0
  148. /package/{commonjs → out/commonjs}/package/module.f.d.mts +0 -0
  149. /package/{commonjs → out/commonjs}/package/test.f.d.mts +0 -0
  150. /package/{commonjs → out/commonjs}/path/module.f.d.mts +0 -0
  151. /package/{commonjs → out/commonjs}/path/test.f.d.mts +0 -0
  152. /package/{commonjs → out/commonjs}/test.d.mts +0 -0
  153. /package/{dev → out/dev}/index.d.mts +0 -0
  154. /package/{dev → out/dev}/module.d.mts +0 -0
  155. /package/{dev → out/dev}/module.f.d.mts +0 -0
  156. /package/{dev → out/dev}/test/module.f.d.mts +0 -0
  157. /package/{dev → out/dev}/test.d.mts +0 -0
  158. /package/{dev → out/dev}/test.f.d.mts +0 -0
  159. /package/{djs → out/djs}/module.f.d.mts +0 -0
  160. /package/{djs → out/djs}/parser/module.f.d.mts +0 -0
  161. /package/{djs → out/djs}/parser/test.f.d.mts +0 -0
  162. /package/{djs → out/djs}/test.f.d.mts +0 -0
  163. /package/{djs → out/djs}/tokenizer/module.f.d.mts +0 -0
  164. /package/{djs → out/djs}/tokenizer/test.f.d.mts +0 -0
  165. /package/{fsc → out/fsc}/module.f.d.mts +0 -0
  166. /package/{fsc → out/fsc}/test.f.d.mts +0 -0
  167. /package/{fsm → out/fsm}/module.f.d.mts +0 -0
  168. /package/{fsm → out/fsm}/test.f.d.mts +0 -0
  169. /package/{html → out/html}/module.f.d.mts +0 -0
  170. /package/{html → out/html}/test.f.d.mts +0 -0
  171. /package/{issues → out/issues}/test.f.d.mts +0 -0
  172. /package/{js → out/js}/tokenizer/module.f.d.mts +0 -0
  173. /package/{js → out/js}/tokenizer/test.f.d.mts +0 -0
  174. /package/{json → out/json}/module.f.d.mts +0 -0
  175. /package/{json → out/json}/parser/module.f.d.mts +0 -0
  176. /package/{json → out/json}/parser/test.f.d.mts +0 -0
  177. /package/{json → out/json}/serializer/module.f.d.mts +0 -0
  178. /package/{json → out/json}/serializer/test.f.d.mts +0 -0
  179. /package/{json → out/json}/test.f.d.mts +0 -0
  180. /package/{json → out/json}/tokenizer/module.f.d.mts +0 -0
  181. /package/{json → out/json}/tokenizer/test.f.d.mts +0 -0
  182. /package/{nanvm-lib → out/nanvm-lib}/tests/test.f.d.mts +0 -0
  183. /package/{nodejs → out/nodejs}/version/main.d.mts +0 -0
  184. /package/{nodejs → out/nodejs}/version/module.f.d.mts +0 -0
  185. /package/{nodejs → out/nodejs}/version/test.f.d.mts +0 -0
  186. /package/{prime_field → out/prime_field}/module.f.d.mts +0 -0
  187. /package/{prime_field → out/prime_field}/test.f.d.mts +0 -0
  188. /package/{secp → out/secp}/module.f.d.mts +0 -0
  189. /package/{secp → out/secp}/test.f.d.mts +0 -0
  190. /package/{sha2 → out/sha2}/module.f.d.mts +0 -0
  191. /package/{sha2 → out/sha2}/test.f.d.mts +0 -0
  192. /package/{text → out/text}/ascii/module.f.d.mts +0 -0
  193. /package/{text → out/text}/ascii/test.f.d.mts +0 -0
  194. /package/{text → out/text}/module.f.d.mts +0 -0
  195. /package/{text → out/text}/sgr/module.f.d.mts +0 -0
  196. /package/{text → out/text}/test.f.d.mts +0 -0
  197. /package/{text → out/text}/utf16/module.f.d.mts +0 -0
  198. /package/{text → out/text}/utf16/test.f.d.mts +0 -0
  199. /package/{text → out/text}/utf8/module.f.d.mts +0 -0
  200. /package/{text → out/text}/utf8/test.f.d.mts +0 -0
  201. /package/{types → out/types}/array/module.f.d.mts +0 -0
  202. /package/{types → out/types}/array/test.f.d.mts +0 -0
  203. /package/{types → out/types}/bigfloat/module.f.d.mts +0 -0
  204. /package/{types → out/types}/bigfloat/test.f.d.mts +0 -0
  205. /package/{types → out/types}/bigint/module.f.d.mts +0 -0
  206. /package/{types → out/types}/bigint/test.f.d.mts +0 -0
  207. /package/{types → out/types}/btree/find/module.f.d.mts +0 -0
  208. /package/{types → out/types}/btree/find/test.f.d.mts +0 -0
  209. /package/{types → out/types}/btree/module.f.d.mts +0 -0
  210. /package/{types → out/types}/btree/remove/module.f.d.mts +0 -0
  211. /package/{types → out/types}/btree/remove/test.f.d.mts +0 -0
  212. /package/{types → out/types}/btree/set/module.f.d.mts +0 -0
  213. /package/{types → out/types}/btree/set/test.f.d.mts +0 -0
  214. /package/{types → out/types}/btree/test.f.d.mts +0 -0
  215. /package/{types → out/types}/btree/types/module.f.d.mts +0 -0
  216. /package/{types → out/types}/byte_set/module.f.d.mts +0 -0
  217. /package/{types → out/types}/byte_set/test.f.d.mts +0 -0
  218. /package/{types → out/types}/function/compare/module.f.d.mts +0 -0
  219. /package/{types → out/types}/function/compare/test.f.d.mts +0 -0
  220. /package/{types → out/types}/function/module.f.d.mts +0 -0
  221. /package/{types → out/types}/function/operator/module.f.d.mts +0 -0
  222. /package/{types → out/types}/function/test.f.d.mts +0 -0
  223. /package/{types → out/types}/list/module.f.d.mts +0 -0
  224. /package/{types → out/types}/list/test.f.d.mts +0 -0
  225. /package/{types → out/types}/map/module.f.d.mts +0 -0
  226. /package/{types → out/types}/map/test.f.d.mts +0 -0
  227. /package/{types → out/types}/nibble_set/module.f.d.mts +0 -0
  228. /package/{types → out/types}/nibble_set/test.f.d.mts +0 -0
  229. /package/{types → out/types}/nullable/module.f.d.mts +0 -0
  230. /package/{types → out/types}/nullable/test.f.d.mts +0 -0
  231. /package/{types → out/types}/number/module.f.d.mts +0 -0
  232. /package/{types → out/types}/number/test.f.d.mts +0 -0
  233. /package/{types → out/types}/object/module.f.d.mts +0 -0
  234. /package/{types → out/types}/object/test.f.d.mts +0 -0
  235. /package/{types → out/types}/range/module.f.d.mts +0 -0
  236. /package/{types → out/types}/range/test.f.d.mts +0 -0
  237. /package/{types → out/types}/range_map/module.f.d.mts +0 -0
  238. /package/{types → out/types}/range_map/test.f.d.mts +0 -0
  239. /package/{types → out/types}/result/module.d.mts +0 -0
  240. /package/{types → out/types}/result/module.f.d.mts +0 -0
  241. /package/{types → out/types}/sorted_list/module.f.d.mts +0 -0
  242. /package/{types → out/types}/sorted_list/test.f.d.mts +0 -0
  243. /package/{types → out/types}/sorted_set/module.f.d.mts +0 -0
  244. /package/{types → out/types}/sorted_set/test.f.d.mts +0 -0
  245. /package/{types → out/types}/string/module.f.d.mts +0 -0
  246. /package/{types → out/types}/string/test.f.d.mts +0 -0
  247. /package/{types → out/types}/string_set/module.f.d.mts +0 -0
  248. /package/{types → out/types}/string_set/test.f.d.mts +0 -0
@@ -0,0 +1,401 @@
1
+ import * as _ from './module.f.mjs';
2
+ import * as json from '../../json/module.f.mjs';
3
+ import * as o from '../object/module.f.mjs';
4
+ const { sort } = o;
5
+ import * as operator from '../function/operator/module.f.mjs';
6
+ const { addition, strictEqual, reduceToScan } = operator;
7
+ /** @type {(sequence: _.List<json.Unknown>) => string} */
8
+ const stringify = sequence => json.stringify(sort)(_.toArray(sequence));
9
+ const stringifyTest = () => {
10
+ const s = stringify([1, 2, 3]);
11
+ if (s !== '[1,2,3]') {
12
+ throw s;
13
+ }
14
+ };
15
+ const cycle = () => {
16
+ const x = stringify(_.toArray(_.take(10)(_.cycle([1, 2, 3]))));
17
+ if (x !== '[1,2,3,1,2,3,1,2,3,1]') {
18
+ throw x;
19
+ }
20
+ };
21
+ const countdown = () => {
22
+ const result = stringify(_.countdown(10));
23
+ if (result !== '[9,8,7,6,5,4,3,2,1,0]') {
24
+ throw result;
25
+ }
26
+ };
27
+ const flat = () => {
28
+ const result = stringify(_.flat([[1, 2, 3], [4, 5], [6], [], [7, 8, 9]]));
29
+ if (result !== '[1,2,3,4,5,6,7,8,9]') {
30
+ throw result;
31
+ }
32
+ };
33
+ const concat = () => {
34
+ const result = _.concat([1])([2]);
35
+ const x = _.next(result);
36
+ if (x === null) {
37
+ throw x;
38
+ }
39
+ if (x.first !== 1) {
40
+ throw x;
41
+ }
42
+ };
43
+ const flatMap = () => {
44
+ const result = stringify(_.flatMap(x => [x, x * 2, x * 3])([0, 1, 2, 3]));
45
+ if (result !== '[0,0,0,1,2,3,2,4,6,3,6,9]') {
46
+ throw result;
47
+ }
48
+ };
49
+ const take = [
50
+ () => {
51
+ const result = stringify(_.take(3)([1, 2, 3, 4, 5, 6, 7, 8, 9]));
52
+ if (result !== '[1,2,3]') {
53
+ throw result;
54
+ }
55
+ },
56
+ () => {
57
+ const result = stringify(_.take(20)([1, 2, 3, 4, 5, 6, 7, 8, 9]));
58
+ if (result !== '[1,2,3,4,5,6,7,8,9]') {
59
+ throw result;
60
+ }
61
+ },
62
+ () => {
63
+ const result = stringify(_.take(0)([1, 2, 3, 4, 5, 6, 7, 8, 9]));
64
+ if (result !== '[]') {
65
+ throw result;
66
+ }
67
+ }
68
+ ];
69
+ const find = [
70
+ () => {
71
+ const result = _.find(null)(x => x % 2 === 0)([1, 3, 5, 7]);
72
+ if (result !== null) {
73
+ throw result;
74
+ }
75
+ },
76
+ () => {
77
+ const result = _.find(null)(x => x % 2 === 0)([1, 2, 3, 4]);
78
+ if (result !== 2) {
79
+ throw result;
80
+ }
81
+ }
82
+ ];
83
+ const takeWhile = [
84
+ () => {
85
+ const result = stringify(_.takeWhile(x => x < 10)([1, 2, 3, 4, 5, 10, 11]));
86
+ if (result !== '[1,2,3,4,5]') {
87
+ throw result;
88
+ }
89
+ },
90
+ () => {
91
+ const result = stringify(_.takeWhile(x => x < 6)([1, 2, 3, 4, 5, 6, 7, 8, 9]));
92
+ if (result !== '[1,2,3,4,5]') {
93
+ throw result;
94
+ }
95
+ }
96
+ ];
97
+ const dropWhile = () => {
98
+ const result = stringify(_.dropWhile(x => x < 10)([1, 2, 3, 4, 5, 10, 11]));
99
+ if (result !== '[10,11]') {
100
+ throw result;
101
+ }
102
+ };
103
+ const drop = [
104
+ () => {
105
+ const result = stringify(_.drop(3)([1, 2, 3, 4, 5, 10, 11]));
106
+ if (result !== '[4,5,10,11]') {
107
+ throw result;
108
+ }
109
+ },
110
+ () => {
111
+ const result = stringify(_.drop(0)([1, 2, 3, 4, 5, 10, 11]));
112
+ if (result !== '[1,2,3,4,5,10,11]') {
113
+ throw result;
114
+ }
115
+ },
116
+ () => {
117
+ const result = stringify(_.drop(10)([1, 2, 3, 4, 5, 10, 11]));
118
+ if (result !== '[]') {
119
+ throw result;
120
+ }
121
+ }
122
+ ];
123
+ const additionTests = [
124
+ () => {
125
+ const op = reduceToScan(addition);
126
+ const result = stringify(_.scan(op)([2, 3, 4, 5]));
127
+ if (result !== '[2,5,9,14]') {
128
+ throw result;
129
+ }
130
+ },
131
+ () => {
132
+ const result = _.reduce(addition)(null)([2, 3, 4, 5]);
133
+ if (result !== 14) {
134
+ throw result;
135
+ }
136
+ },
137
+ () => {
138
+ const result = _.reduce(addition)(null)([]);
139
+ if (result !== null) {
140
+ throw result;
141
+ }
142
+ }
143
+ ];
144
+ const entries = [
145
+ () => {
146
+ const result = stringify(_.entries([]));
147
+ if (result !== '[]') {
148
+ throw result;
149
+ }
150
+ },
151
+ () => {
152
+ const result = stringify(_.entries(['hello', 'world']));
153
+ if (result !== '[[0,"hello"],[1,"world"]]') {
154
+ throw result;
155
+ }
156
+ }
157
+ ];
158
+ const reverse = [
159
+ () => {
160
+ const result = stringify(_.reverse([]));
161
+ if (result !== '[]') {
162
+ throw result;
163
+ }
164
+ },
165
+ () => {
166
+ const result = stringify(_.reverse([1, 2, 3, 4, 5]));
167
+ if (result !== '[5,4,3,2,1]') {
168
+ throw result;
169
+ }
170
+ }
171
+ ];
172
+ const zip = [
173
+ () => {
174
+ const result = stringify(_.zip([0, 1, 2])(['a', 'b', 'c', 'd']));
175
+ if (result !== '[[0,"a"],[1,"b"],[2,"c"]]') {
176
+ throw result;
177
+ }
178
+ },
179
+ () => {
180
+ const result = stringify(_.zip([0, 1, 2])(['a', 'b']));
181
+ if (result !== '[[0,"a"],[1,"b"]]') {
182
+ throw result;
183
+ }
184
+ }
185
+ ];
186
+ const logic = () => {
187
+ const map5 = _.map(x => x > 5);
188
+ return [
189
+ () => {
190
+ const result = _.some(map5([0, 1, 7]));
191
+ if (!result) {
192
+ throw result;
193
+ }
194
+ },
195
+ () => {
196
+ const result = _.some(map5([0, 1, 4]));
197
+ if (result) {
198
+ throw result;
199
+ }
200
+ },
201
+ () => {
202
+ const result = _.some(map5([]));
203
+ if (result) {
204
+ throw result;
205
+ }
206
+ },
207
+ () => {
208
+ const result = _.every(map5([0, 1, 7]));
209
+ if (result) {
210
+ throw result;
211
+ }
212
+ },
213
+ () => {
214
+ const result = _.every(map5([6, 11, 7]));
215
+ if (!result) {
216
+ throw result;
217
+ }
218
+ },
219
+ () => {
220
+ const result = _.every(map5([]));
221
+ if (!result) {
222
+ throw result;
223
+ }
224
+ }
225
+ ];
226
+ };
227
+ // stress tests
228
+ const stress = () => ({
229
+ toArray: () => {
230
+ // 200_000_000 is too much
231
+ const n = 100_000_000;
232
+ const result = _.toArray(_.countdown(n));
233
+ if (result.length !== n) {
234
+ throw result.length;
235
+ }
236
+ const len = _.length(_.filter(x => x > n)(result));
237
+ if (len !== 0) {
238
+ throw len;
239
+ }
240
+ },
241
+ first: () => {
242
+ // 100_000_000 is too much
243
+ const n = 50_000_000;
244
+ const result = _.toArray(_.countdown(n));
245
+ if (result.length !== n) {
246
+ throw result.length;
247
+ }
248
+ const first = _.first(null)(result);
249
+ if (first !== n - 1) {
250
+ throw first;
251
+ }
252
+ },
253
+ concatBack: () => {
254
+ /** @type {_.List<number>} */
255
+ let sequence = [];
256
+ // 20_000_000 is too much
257
+ // 10_000_000 is too much for Deno 1
258
+ for (let i = 0; i < 5_000_000; ++i) {
259
+ sequence = _.concat(sequence)([i]);
260
+ }
261
+ const r = _.toArray(sequence);
262
+ },
263
+ flatToArray: () => {
264
+ /** @type {_.List<number>} */
265
+ let sequence = [];
266
+ // 4_000_000 is too much
267
+ for (let i = 0; i < 2_000_000; ++i) {
268
+ sequence = _.flat([sequence, [i]]);
269
+ }
270
+ const r = _.toArray(sequence);
271
+ },
272
+ flatNext: () => {
273
+ /** @type {_.List<number>} */
274
+ let sequence = [];
275
+ // 4_000_000 is too much
276
+ for (let i = 0; i < 2_000_000; ++i) {
277
+ sequence = _.flat([sequence, [i]]);
278
+ }
279
+ const a = _.next(sequence);
280
+ },
281
+ concatFront: () => {
282
+ /** @type {_.List<number>} */
283
+ let sequence = [];
284
+ // 20_000_000 is too much
285
+ for (let i = 0; i < 10_000_000; ++i) {
286
+ sequence = _.concat([i])(sequence);
287
+ }
288
+ const a = _.next(sequence);
289
+ },
290
+ flatFront: () => {
291
+ /** @type {_.List<number>} */
292
+ let sequence = [];
293
+ // 10_000_000 is too much
294
+ for (let i = 0; i < 5_000_000; ++i) {
295
+ sequence = _.flat([[i], sequence]);
296
+ }
297
+ const a = _.next(sequence);
298
+ },
299
+ filterMap: () => {
300
+ // 100_000_000 is too much
301
+ const n = 50_000_000;
302
+ const result = _.toArray(_.countdown(n));
303
+ if (result.length !== n) {
304
+ throw result.length;
305
+ }
306
+ const len = _.length(_.filterMap(() => null)(result));
307
+ if (len !== 0) {
308
+ throw len;
309
+ }
310
+ },
311
+ dropWhile: () => {
312
+ // 50_000_000 is too much
313
+ const n = 20_000_000;
314
+ const result = _.toArray(_.countdown(n));
315
+ if (result.length !== n) {
316
+ throw result.length;
317
+ }
318
+ const len = _.length(_.dropWhile(() => true)(result));
319
+ if (len !== 0) {
320
+ throw len;
321
+ }
322
+ },
323
+ reverse: () => {
324
+ // 10_000_000 is too much
325
+ const n = 5_000_000;
326
+ const result = _.toArray(_.reverse(_.countdown(n)));
327
+ if (result.length !== n) {
328
+ throw result.length;
329
+ }
330
+ }
331
+ });
332
+ export default {
333
+ stringifyTest,
334
+ cycle,
335
+ countdown,
336
+ flat,
337
+ concat,
338
+ flatMap,
339
+ take,
340
+ find,
341
+ takeWhile,
342
+ dropWhile,
343
+ drop,
344
+ additionTests,
345
+ entries,
346
+ reverse,
347
+ zip,
348
+ logic,
349
+ strictEqual: [
350
+ () => {
351
+ const result = _.equal(strictEqual)([1])([2, 3]);
352
+ if (result) {
353
+ throw result;
354
+ }
355
+ },
356
+ () => {
357
+ const result = _.equal(strictEqual)([1, 3])([1]);
358
+ if (result) {
359
+ throw result;
360
+ }
361
+ },
362
+ () => {
363
+ const result = _.equal(strictEqual)([15, 78])([15, 78]);
364
+ if (!result) {
365
+ throw result;
366
+ }
367
+ },
368
+ () => {
369
+ const result = _.equal(strictEqual)([])([]);
370
+ if (!result) {
371
+ throw result;
372
+ }
373
+ }
374
+ ],
375
+ isEmpty: [
376
+ () => {
377
+ const result = _.isEmpty(() => []);
378
+ if (result !== true) {
379
+ throw result;
380
+ }
381
+ },
382
+ () => {
383
+ const result = _.isEmpty(() => [2]);
384
+ if (result !== false) {
385
+ throw result;
386
+ }
387
+ }
388
+ ],
389
+ length: () => {
390
+ if (_.length([1, 2, 3]) !== 3) {
391
+ throw 3;
392
+ }
393
+ if (_.length(null) !== 0) {
394
+ throw 0;
395
+ }
396
+ if (_.length(_.flat([[1, 3], null, () => [3], _.concat([12])([4, 89])])) !== 6) {
397
+ throw 6;
398
+ }
399
+ },
400
+ // stress
401
+ };
@@ -0,0 +1,54 @@
1
+ // @ts-self-types="./module.f.d.mts"
2
+ import * as BtreeTypes from '../btree/types/module.f.mjs';
3
+ import * as btf from '../btree/find/module.f.mjs';
4
+ const { value, find } = btf;
5
+ import * as bts from '../btree/set/module.f.mjs';
6
+ const { set } = bts;
7
+ import * as btr from '../btree/remove/module.f.mjs';
8
+ const { remove: btreeRemove } = btr;
9
+ import * as bt from '../btree/module.f.mjs';
10
+ const { values } = bt;
11
+ import * as Compare from '../function/compare/module.f.mjs';
12
+ import * as s from '../string/module.f.mjs';
13
+ const { cmp } = s;
14
+ import * as list from '../list/module.f.mjs';
15
+ const { fold } = list;
16
+ import * as Operator from '../function/operator/module.f.mjs';
17
+ /** @typedef {Compare.Sign} Sign */
18
+ /**
19
+ * @template T
20
+ * @typedef {Compare.Compare<T>} Cmp
21
+ */
22
+ /**
23
+ * @template T
24
+ * @typedef {readonly[string, T]} Entry
25
+ */
26
+ /**
27
+ * @template T
28
+ * @typedef {BtreeTypes.Tree<Entry<T>>} Map
29
+ */
30
+ /** @type {(a: string) => <T>(b: Entry<T>) => Sign} */
31
+ const keyCmp = a => ([b]) => cmp(a)(b);
32
+ /** @type {(name: string) => <T>(map: Map<T>) => T|null} */
33
+ export const at = name => map => {
34
+ if (map === null) {
35
+ return null;
36
+ }
37
+ const result = value(find(keyCmp(name))(map).first);
38
+ return result === null ? null : result[1];
39
+ };
40
+ /** @type {<T>(reduce: Operator.Reduce<T>) => (entry: Entry<T>) => (map: Map<T>) => Map<T>} */
41
+ const setReduceEntry = reduce => entry => set(keyCmp(entry[0]))(old => old === null ? entry : [old[0], reduce(old[1])(entry[1])]);
42
+ /** @type {<T>(reduce: Operator.Reduce<T>) => (name: string) => (value: T) => (map: Map<T>) => Map<T>} */
43
+ export const setReduce = reduce => name => value => setReduceEntry(reduce)([name, value]);
44
+ /** @type {<T>(a: T) => (b: T) => T} */
45
+ const replace = () => b => b;
46
+ /** @type {(name: string) => <T>(value: T) => (map: Map<T>) => Map<T>} */
47
+ export const setReplace = name => value => setReduceEntry(replace)([name, value]);
48
+ /** @type {<T>(map: Map<T>) => list.List<Entry<T>>} */
49
+ export const entries = values;
50
+ /** @type {<T>(entries: list.List<Entry<T>>) => Map<T>} */
51
+ export const fromEntries = fold(setReduceEntry(replace))(null);
52
+ /** @type {(name: string) => <T>(map: Map<T>) => Map<T>} */
53
+ export const remove = name => btreeRemove(keyCmp(name));
54
+ export const empty = null;
@@ -0,0 +1,115 @@
1
+ import * as _ from './module.f.mjs';
2
+ const { at, setReplace, setReduce, empty, entries, remove } = _;
3
+ import * as seq from '../list/module.f.mjs';
4
+ export default {
5
+ main: [
6
+ () => {
7
+ let m = setReplace('a')(1)(null);
8
+ if (at('a')(m) !== 1) {
9
+ throw 'error';
10
+ }
11
+ if (at('b')(m) !== null) {
12
+ throw 'error';
13
+ }
14
+ m = setReplace('b')(2)(m);
15
+ if (at('a')(m) !== 1) {
16
+ throw 'error';
17
+ }
18
+ if (at('b')(m) !== 2) {
19
+ throw 'error';
20
+ }
21
+ if (at('c')(m) !== null) {
22
+ throw 'error';
23
+ }
24
+ m = setReplace('z')(3)(m);
25
+ if (at('a')(m) !== 1) {
26
+ throw 'error';
27
+ }
28
+ if (at('b')(m) !== 2) {
29
+ throw 'error';
30
+ }
31
+ if (at('z')(m) !== 3) {
32
+ throw 'error';
33
+ }
34
+ if (at('')(m) !== null) {
35
+ throw 'error';
36
+ }
37
+ m = setReplace('')(4)(m);
38
+ if (at('a')(m) !== 1) {
39
+ throw 'error';
40
+ }
41
+ if (at('b')(m) !== 2) {
42
+ throw 'error';
43
+ }
44
+ if (at('z')(m) !== 3) {
45
+ throw 'error';
46
+ }
47
+ if (at('')(m) !== 4) {
48
+ throw 'error';
49
+ }
50
+ if (at('Hello world!')(m) !== null) {
51
+ throw 'error';
52
+ }
53
+ m = setReplace('Hello world!')(42)(m);
54
+ if (at('a')(m) !== 1) {
55
+ throw 'error';
56
+ }
57
+ if (at('b')(m) !== 2) {
58
+ throw 'error';
59
+ }
60
+ if (at('z')(m) !== 3) {
61
+ throw 'error';
62
+ }
63
+ if (at('')(m) !== 4) {
64
+ throw 'error';
65
+ }
66
+ if (at('Hello world!')(m) !== 42) {
67
+ throw 'error';
68
+ }
69
+ if (at('x')(m) !== null) {
70
+ throw 'error';
71
+ }
72
+ // console.log(Array.from(m.entries()))
73
+ m = remove('Hello world!')(m);
74
+ if (at('Hello world!')(m) !== null) {
75
+ throw m;
76
+ }
77
+ m = setReduce(a => b => a + b)('a')(43)(m);
78
+ if (at('a')(m) !== 44) {
79
+ throw 'error';
80
+ }
81
+ },
82
+ () => {
83
+ let m = setReplace('x')(12)(null);
84
+ m = setReplace('y')(44)(m);
85
+ if (at('x')(m) !== 12) {
86
+ throw 'error';
87
+ }
88
+ if (at('y')(m) !== 44) {
89
+ throw 'error';
90
+ }
91
+ if (at('a')(m) !== null) {
92
+ throw 'error';
93
+ }
94
+ const e = seq.toArray(entries(m));
95
+ if (e.length !== 2) {
96
+ throw 'error';
97
+ }
98
+ },
99
+ ],
100
+ stress: () => {
101
+ /** @type {import('./module.f.mjs').Map<number>} */
102
+ let m = empty;
103
+ for (let i = 0; i < 100_000; ++i) {
104
+ m = setReplace((i * i).toString())(i)(m);
105
+ /*
106
+ console.log()
107
+ console.log(`# ${i}`)
108
+ console.log()
109
+ for (const e of m.struct()) {
110
+ console.log(e)
111
+ }
112
+ */
113
+ }
114
+ }
115
+ };
@@ -0,0 +1,19 @@
1
+ // @ts-self-types="./module.f.d.mts"
2
+ /** @typedef {number} NibbleSet */
3
+ /** @typedef {number} Nibble */
4
+ export const empty = 0;
5
+ export const universe = 0xFFFF;
6
+ /** @type {(n: Nibble) => NibbleSet} */
7
+ const one = n => 1 << n;
8
+ /** @type {(n: Nibble) => (s: NibbleSet) => boolean} */
9
+ export const has = n => s => ((s >> n) & 1) === 1;
10
+ /** @type {(n: Nibble) => (s: NibbleSet) => NibbleSet} */
11
+ export const set = n => s => s | one(n);
12
+ /** @type {(n: NibbleSet) => NibbleSet} */
13
+ export const complement = s => universe ^ s;
14
+ /** @type {(n: Nibble) => (s: NibbleSet) => NibbleSet} */
15
+ export const unset = n => s => s & complement(one(n));
16
+ /** @type {(r: readonly[number, number]) => NibbleSet} */
17
+ const range = ([a, b]) => one(b - a + 1) - 1 << a;
18
+ /** @type {(r: readonly[number, number]) => (s: NibbleSet) => NibbleSet} */
19
+ export const setRange = r => s => s | range(r);
@@ -0,0 +1,90 @@
1
+ import * as list from '../list/module.f.mjs';
2
+ const { every, map, countdown } = list;
3
+ import * as _ from './module.f.mjs';
4
+ export default {
5
+ has: () => {
6
+ if (_.has(0)(_.empty)) {
7
+ throw _.empty;
8
+ }
9
+ if (_.has(1)(_.empty)) {
10
+ throw _.empty;
11
+ }
12
+ if (_.has(15)(_.empty)) {
13
+ throw _.empty;
14
+ }
15
+ },
16
+ set: [
17
+ () => {
18
+ const s = _.set(0)(_.empty);
19
+ if (s !== 1) {
20
+ throw s;
21
+ }
22
+ if (!_.has(0)(s)) {
23
+ throw s;
24
+ }
25
+ if (_.has(1)(s)) {
26
+ throw s;
27
+ }
28
+ if (_.has(15)(s)) {
29
+ throw s;
30
+ }
31
+ },
32
+ () => {
33
+ const s = _.set(15)(_.empty);
34
+ if (s !== 0x8000) {
35
+ throw s;
36
+ }
37
+ if (_.has(0)(s)) {
38
+ throw s;
39
+ }
40
+ if (_.has(1)(s)) {
41
+ throw s;
42
+ }
43
+ if (!_.has(15)(s)) {
44
+ throw s;
45
+ }
46
+ }
47
+ ],
48
+ unset: () => [
49
+ () => {
50
+ const a = _.set(0)(_.empty);
51
+ const result = _.unset(0)(a);
52
+ if (result !== 0) {
53
+ throw result;
54
+ }
55
+ },
56
+ () => {
57
+ const a = _.set(15)(_.empty);
58
+ const result = _.unset(15)(a);
59
+ if (result !== 0) {
60
+ throw result;
61
+ }
62
+ }
63
+ ],
64
+ setRange: () => {
65
+ const result = _.setRange([2, 5])(_.empty);
66
+ if (result !== 60) {
67
+ throw result;
68
+ }
69
+ },
70
+ universe: () => {
71
+ const x = every(map(v => _.has(v)(_.universe))(countdown(16)));
72
+ if (!x) {
73
+ throw x;
74
+ }
75
+ },
76
+ compliment: {
77
+ empty: () => {
78
+ const r = _.complement(_.empty);
79
+ if (r !== _.universe) {
80
+ throw r;
81
+ }
82
+ },
83
+ universe: () => {
84
+ const r = _.complement(_.universe);
85
+ if (r !== _.empty) {
86
+ throw r;
87
+ }
88
+ },
89
+ }
90
+ };
@@ -0,0 +1,9 @@
1
+ // @ts-self-types="./module.f.d.mts"
2
+ /**
3
+ * @template T
4
+ * @typedef {T|null} Nullable
5
+ */
6
+ /** @type {<T, R>(f: (value: T) => R) => (value: Nullable<T>) => Nullable<R>} */
7
+ export const map = f => value => value === null ? null : f(value);
8
+ /** @type {<T, R>(f: (_: T) => R) => (none: () => R) => (_: Nullable<T>) => Nullable<R>} */
9
+ export const match = f => none => value => value === null ? none() : f(value);
@@ -0,0 +1,12 @@
1
+ import * as _ from './module.f.mjs';
2
+ export default () => {
3
+ const optionSq = _.map(v => v * v);
4
+ const sq3 = optionSq(3);
5
+ if (sq3 !== 9) {
6
+ throw sq3;
7
+ }
8
+ const sqNull = optionSq(null);
9
+ if (sqNull !== null) {
10
+ throw sqNull;
11
+ }
12
+ };