@grain/stdlib 0.4.4 → 0.5.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 (97) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/LICENSE +1 -1
  3. package/array.gr +92 -73
  4. package/array.md +18 -18
  5. package/bigint.gr +497 -0
  6. package/bigint.md +811 -0
  7. package/buffer.gr +56 -217
  8. package/buffer.md +24 -17
  9. package/bytes.gr +103 -205
  10. package/bytes.md +19 -0
  11. package/char.gr +152 -166
  12. package/char.md +200 -0
  13. package/exception.md +6 -0
  14. package/float32.gr +159 -82
  15. package/float32.md +315 -0
  16. package/float64.gr +163 -82
  17. package/float64.md +315 -0
  18. package/hash.gr +53 -49
  19. package/int32.gr +479 -230
  20. package/int32.md +937 -0
  21. package/int64.gr +479 -230
  22. package/int64.md +937 -0
  23. package/list.gr +530 -116
  24. package/list.md +1141 -0
  25. package/map.gr +302 -121
  26. package/map.md +525 -0
  27. package/number.gr +51 -57
  28. package/number.md +37 -3
  29. package/option.gr +25 -25
  30. package/option.md +1 -1
  31. package/package.json +3 -3
  32. package/pervasives.gr +504 -52
  33. package/pervasives.md +1116 -0
  34. package/queue.gr +8 -1
  35. package/queue.md +10 -0
  36. package/random.gr +196 -0
  37. package/random.md +179 -0
  38. package/range.gr +26 -26
  39. package/regex.gr +1833 -842
  40. package/regex.md +11 -11
  41. package/result.md +1 -1
  42. package/runtime/bigint.gr +2045 -0
  43. package/runtime/bigint.md +326 -0
  44. package/runtime/dataStructures.gr +99 -279
  45. package/runtime/dataStructures.md +391 -0
  46. package/runtime/debug.gr +0 -1
  47. package/runtime/debug.md +6 -0
  48. package/runtime/equal.gr +40 -37
  49. package/runtime/equal.md +6 -0
  50. package/runtime/exception.gr +28 -15
  51. package/runtime/exception.md +30 -0
  52. package/runtime/gc.gr +50 -20
  53. package/runtime/gc.md +36 -0
  54. package/runtime/malloc.gr +32 -22
  55. package/runtime/malloc.md +55 -0
  56. package/runtime/numberUtils.gr +297 -142
  57. package/runtime/numberUtils.md +54 -0
  58. package/runtime/numbers.gr +1204 -453
  59. package/runtime/numbers.md +300 -0
  60. package/runtime/string.gr +193 -228
  61. package/runtime/string.md +24 -0
  62. package/runtime/stringUtils.gr +62 -38
  63. package/runtime/stringUtils.md +6 -0
  64. package/runtime/unsafe/constants.gr +17 -0
  65. package/runtime/unsafe/constants.md +72 -0
  66. package/runtime/unsafe/conv.gr +10 -10
  67. package/runtime/unsafe/conv.md +71 -0
  68. package/runtime/unsafe/errors.md +204 -0
  69. package/runtime/unsafe/memory.gr +14 -3
  70. package/runtime/unsafe/memory.md +54 -0
  71. package/runtime/unsafe/printWasm.gr +4 -4
  72. package/runtime/unsafe/printWasm.md +24 -0
  73. package/runtime/unsafe/tags.gr +11 -10
  74. package/runtime/unsafe/tags.md +120 -0
  75. package/runtime/unsafe/wasmf32.gr +9 -2
  76. package/runtime/unsafe/wasmf32.md +168 -0
  77. package/runtime/unsafe/wasmf64.gr +9 -2
  78. package/runtime/unsafe/wasmf64.md +168 -0
  79. package/runtime/unsafe/wasmi32.gr +65 -47
  80. package/runtime/unsafe/wasmi32.md +282 -0
  81. package/runtime/unsafe/wasmi64.gr +78 -50
  82. package/runtime/unsafe/wasmi64.md +300 -0
  83. package/runtime/utils/printing.gr +62 -0
  84. package/runtime/utils/printing.md +18 -0
  85. package/runtime/wasi.gr +200 -46
  86. package/runtime/wasi.md +839 -0
  87. package/set.gr +125 -121
  88. package/set.md +24 -21
  89. package/stack.gr +29 -29
  90. package/stack.md +4 -6
  91. package/string.gr +434 -415
  92. package/string.md +3 -3
  93. package/sys/file.gr +477 -482
  94. package/sys/process.gr +33 -47
  95. package/sys/random.gr +48 -20
  96. package/sys/random.md +38 -0
  97. package/sys/time.gr +12 -28
package/CHANGELOG.md CHANGED
@@ -1,5 +1,92 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.0](https://github.com/grain-lang/grain/compare/stdlib-v0.4.6...stdlib-v0.5.0) (2022-06-05)
4
+
5
+
6
+ ### ⚠ BREAKING CHANGES
7
+
8
+ * **stdlib:** Use explicit exports for Pervasives (#1301)
9
+ * **stdlib:** Remove `sum` function from the List module (#1300)
10
+ * **stdlib:** Ensure Void return for forEach functions in List module (#1307)
11
+ * **stdlib:** Provide correct types for BigInt operations (#1297)
12
+ * **grainfmt:** Replace `--in-place` flag with `-o` flag
13
+ * **grainfmt:** Remove stdin formatting support
14
+ * **compiler:** Arbitrary-Precision Integer Arithmetic (#1167)
15
+ * Drop node 14 support (#1092)
16
+ * **stdlib:** Add explicit void return type on Set.forEach (#1225)
17
+ * **stdlib:** Add explicit void return type on Map.forEach (#1220)
18
+ * **stdlib:** Add type aliases to regex lib (#1036)
19
+ * **compiler:** Stack-allocated Chars (#1103)
20
+ * **stdlib:** Align Buffer's `addStringSlice` API with String's `slice` (#1136)
21
+ * **graindoc:** Add `--current-version` flag, required for since/history attributes (#1116)
22
+ * **compiler:** Remove decRefIgnoreZeros (#1068)
23
+ * **compiler:** Add `--memory-base` flag (#1115)
24
+ * **compiler:** Re-implement Grain parser (#1033)
25
+
26
+ ### Features
27
+
28
+ * **compiler:** Add `--memory-base` flag ([#1115](https://github.com/grain-lang/grain/issues/1115)) ([0680826](https://github.com/grain-lang/grain/commit/068082663c4387c3ab54c052869e9b9a06b87e26))
29
+ * **compiler:** Arbitrary-Precision Integer Arithmetic ([#1167](https://github.com/grain-lang/grain/issues/1167)) ([6f34de2](https://github.com/grain-lang/grain/commit/6f34de214b28358ea1df553685fa3a19336ddba9))
30
+ * **compiler:** Call known functions across module boundaries ([#1175](https://github.com/grain-lang/grain/issues/1175)) ([b2d7440](https://github.com/grain-lang/grain/commit/b2d744034ec7e0601554531c910e9d0f5451d464))
31
+ * **compiler:** Convert `runtime/dataStructures.gr` to primitives ([#1145](https://github.com/grain-lang/grain/issues/1145)) ([2d43b28](https://github.com/grain-lang/grain/commit/2d43b286141df75f6b92300e48d2bc4804014872))
32
+ * **compiler:** Convert Sys libraries to [@unsafe](https://github.com/unsafe) ([#1272](https://github.com/grain-lang/grain/issues/1272)) ([fcdfc2a](https://github.com/grain-lang/grain/commit/fcdfc2a815be889d5f0424a04dd5b2373dbd983b))
33
+ * **compiler:** Don't close over global values ([#1134](https://github.com/grain-lang/grain/issues/1134)) ([e8caec6](https://github.com/grain-lang/grain/commit/e8caec6c2a5892e955c8827b18d8d436bebe6073))
34
+ * **compiler:** Re-implement Grain parser ([#1033](https://github.com/grain-lang/grain/issues/1033)) ([9dc3c96](https://github.com/grain-lang/grain/commit/9dc3c96f87a0b2affe9db36e1b03360d198f79f1))
35
+ * **compiler:** Stack-allocated Chars ([#1103](https://github.com/grain-lang/grain/issues/1103)) ([095385e](https://github.com/grain-lang/grain/commit/095385e7c67bbc7a417a21acaf6f1c498c75ce63))
36
+ * **graindoc:** Add `--current-version` flag, required for since/history attributes ([#1116](https://github.com/grain-lang/grain/issues/1116)) ([0f681ea](https://github.com/grain-lang/grain/commit/0f681ea140749395f3ce99a460f30778537183ac))
37
+ * **graindoc:** Allow directory input & output ([#1263](https://github.com/grain-lang/grain/issues/1263)) ([d4cb8ab](https://github.com/grain-lang/grain/commit/d4cb8abcb4accafeb3cae0bac77eee9a365e464d))
38
+ * **grainfmt:** Allow directory input & output ([#1274](https://github.com/grain-lang/grain/issues/1274)) ([d3e7a33](https://github.com/grain-lang/grain/commit/d3e7a33b01352a9c2bcc3b17a5b2995451d92221))
39
+ * **grainfmt:** Replace `--in-place` flag with `-o` flag ([d3e7a33](https://github.com/grain-lang/grain/commit/d3e7a33b01352a9c2bcc3b17a5b2995451d92221))
40
+ * **stdlib:** Add module for pseudo-random number generation ([#921](https://github.com/grain-lang/grain/issues/921)) ([db1fa4e](https://github.com/grain-lang/grain/commit/db1fa4e491d35bb582beaba12157884647384a77))
41
+ * **stdlib:** Add unsigned versions of Int32/Int64 comparison operations ([#831](https://github.com/grain-lang/grain/issues/831)) ([5f20868](https://github.com/grain-lang/grain/commit/5f20868e7b6e3f52d62c8531d99d1130ca84961e))
42
+ * **stdlib:** Added Bytes.clear function. Avoid allocation in Buffer.clear ([#1124](https://github.com/grain-lang/grain/issues/1124)) ([4afd17a](https://github.com/grain-lang/grain/commit/4afd17a91e59027fa7af0fe58977bdbe942f8072))
43
+ * **stdlib:** Convert runtime printing utils to [@unsafe](https://github.com/unsafe) ([#1135](https://github.com/grain-lang/grain/issues/1135)) ([403e1d2](https://github.com/grain-lang/grain/commit/403e1d20e2082fe2dcd2721f83f6c2b36d4154bf))
44
+
45
+
46
+ ### Bug Fixes
47
+
48
+ * **cli:** Ensure parent flags are inherited by the format command ([d3e7a33](https://github.com/grain-lang/grain/commit/d3e7a33b01352a9c2bcc3b17a5b2995451d92221))
49
+ * **graindoc:** Add parens around infix operators in titles ([#1303](https://github.com/grain-lang/grain/issues/1303)) ([acba9c1](https://github.com/grain-lang/grain/commit/acba9c1757688756c3ca98b22a0a159b8d8f9e7d))
50
+ * **graindoc:** Preserve indentation in Doc comments during trim ([#1119](https://github.com/grain-lang/grain/issues/1119)) ([b8a6d57](https://github.com/grain-lang/grain/commit/b8a6d57cce274bfbc2cc16c5b25215b042d4264c))
51
+ * **graindoc:** Remove spaces between parens and infix idents ([#1302](https://github.com/grain-lang/grain/issues/1302)) ([95e596f](https://github.com/grain-lang/grain/commit/95e596fa3fdae5a8a0e07d76ff8c11eeab99e8d7))
52
+ * **graindoc:** Use value_descriptions and type_declarations defined by the module signature ([#1241](https://github.com/grain-lang/grain/issues/1241)) ([5896242](https://github.com/grain-lang/grain/commit/5896242c324622f3329c144bd2c9642aade9d049))
53
+ * **grainfmt:** Remove parens around annotated types ([#1109](https://github.com/grain-lang/grain/issues/1109)) ([0ca66bd](https://github.com/grain-lang/grain/commit/0ca66bd43703826f86ef5b28b49d250af219fb0b))
54
+ * **stdlib:** Add explicit void return type on Map.forEach ([#1220](https://github.com/grain-lang/grain/issues/1220)) ([ab2066a](https://github.com/grain-lang/grain/commit/ab2066aadffa8813344d9df7c7a10ec0f76751b6))
55
+ * **stdlib:** Add explicit void return type on Set.forEach ([#1225](https://github.com/grain-lang/grain/issues/1225)) ([694e6cf](https://github.com/grain-lang/grain/commit/694e6cf8fcd061a77b2915dc0ea9e9b1ae143ae4))
56
+ * **stdlib:** Align Buffer's `addStringSlice` API with String's `slice` ([#1136](https://github.com/grain-lang/grain/issues/1136)) ([0c7cb82](https://github.com/grain-lang/grain/commit/0c7cb820d49cda74598680cc614c0d893b4d2b40))
57
+ * **stdlib:** Buffer.toBytes should not expose the raw instance of Bytes used by the buffer ([#1130](https://github.com/grain-lang/grain/issues/1130)) ([d2bb585](https://github.com/grain-lang/grain/commit/d2bb585d3e2092f1331a679f4e84a9500b8c87a5))
58
+ * **stdlib:** Ensure Void return for forEach functions in List module ([#1307](https://github.com/grain-lang/grain/issues/1307)) ([31f480c](https://github.com/grain-lang/grain/commit/31f480c22e0a39b347fc3a48e1d0b5bd40c2f19e))
59
+ * **stdlib:** Fix float printing in dtoa ([#1165](https://github.com/grain-lang/grain/issues/1165)) ([2987210](https://github.com/grain-lang/grain/commit/2987210648873ab474990ff2b7146a489fecb268))
60
+ * **stdlib:** Fixed a memory leak in Buffer.addStringSlice. ([#1122](https://github.com/grain-lang/grain/issues/1122)) ([c4e1911](https://github.com/grain-lang/grain/commit/c4e19110bd9923e58a7953fcbcef18bf07f3efd6))
61
+ * **stdlib:** Fixed length and byteLength for strings over 2GiB. ([#1126](https://github.com/grain-lang/grain/issues/1126)) ([08a9487](https://github.com/grain-lang/grain/commit/08a948709270a9aa4ac853c2887bc652c4734f36))
62
+ * **stdlib:** Make Bytes.length handle sizes over 2GiB ([#1123](https://github.com/grain-lang/grain/issues/1123)) ([d7386eb](https://github.com/grain-lang/grain/commit/d7386eb36c32452d69a734b447015b4db23f1ac4))
63
+ * **stdlib:** Provide correct types for BigInt operations ([#1297](https://github.com/grain-lang/grain/issues/1297)) ([fdd2f1c](https://github.com/grain-lang/grain/commit/fdd2f1c49b938a013d6ae199b5e662cb93d051e6))
64
+ * **stdlib:** Remove intermediate resizes in Buffer.autogrow ([#1125](https://github.com/grain-lang/grain/issues/1125)) ([c1695d0](https://github.com/grain-lang/grain/commit/c1695d066ccd40b3118c5c870353addeef67bfc1))
65
+ * **stdlib:** Use explicit exports for Pervasives ([#1301](https://github.com/grain-lang/grain/issues/1301)) ([bad5897](https://github.com/grain-lang/grain/commit/bad5897062444ec4d4ace805adcd382725b86125))
66
+
67
+
68
+ ### Miscellaneous Chores
69
+
70
+ * **compiler:** Remove decRefIgnoreZeros ([#1068](https://github.com/grain-lang/grain/issues/1068)) ([3ae8eaa](https://github.com/grain-lang/grain/commit/3ae8eaabad4467304c500c2f0cc9c40749d8513b))
71
+ * Drop node 14 support ([#1092](https://github.com/grain-lang/grain/issues/1092)) ([ef4358f](https://github.com/grain-lang/grain/commit/ef4358ff7de14a35edf3e971e04513d497fe1574))
72
+ * **grainfmt:** Remove stdin formatting support ([d3e7a33](https://github.com/grain-lang/grain/commit/d3e7a33b01352a9c2bcc3b17a5b2995451d92221))
73
+ * **stdlib:** Add type aliases to regex lib ([#1036](https://github.com/grain-lang/grain/issues/1036)) ([a926ea5](https://github.com/grain-lang/grain/commit/a926ea5cafa18e46487a585abbdf5460b15b4f48))
74
+ * **stdlib:** Remove `sum` function from the List module ([#1300](https://github.com/grain-lang/grain/issues/1300)) ([9101615](https://github.com/grain-lang/grain/commit/9101615688f20310ae32573f93f36cfcf5c69be1))
75
+
76
+ ### [0.4.6](https://www.github.com/grain-lang/grain/compare/stdlib-v0.4.5...stdlib-v0.4.6) (2022-01-17)
77
+
78
+
79
+ ### Bug Fixes
80
+
81
+ * **grainfmt:** Indent function application args when adding parens ([#1095](https://www.github.com/grain-lang/grain/issues/1095)) ([64af7d3](https://www.github.com/grain-lang/grain/commit/64af7d387dca2fddb9b3d190ccdf5790ec3d8e65))
82
+
83
+ ### [0.4.5](https://www.github.com/grain-lang/grain/compare/stdlib-v0.4.4...stdlib-v0.4.5) (2021-12-31)
84
+
85
+
86
+ ### Features
87
+
88
+ * **stdlib:** Add sign function to Number module ([#1079](https://www.github.com/grain-lang/grain/issues/1079)) ([b6483d5](https://www.github.com/grain-lang/grain/commit/b6483d5046cd1b6b89a717a925594d3b20b05837))
89
+
3
90
  ### [0.4.4](https://www.github.com/grain-lang/grain/compare/stdlib-v0.4.3...stdlib-v0.4.4) (2021-12-11)
4
91
 
5
92
 
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2021 Oscar Spencer <oscar@grain-lang.org> and Philip Blair <philip@grain-lang.org>
3
+ Copyright (c) 2017-2022 Oscar Spencer <oscar@grain-lang.org> and Philip Blair <philip@grain-lang.org>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/array.gr CHANGED
@@ -30,7 +30,7 @@ let initPtr = () => {
30
30
  initPtr()
31
31
 
32
32
  @disableGC
33
- let initLength = (length) => {
33
+ let initLength = length => {
34
34
  let length = WasmI32.fromGrain(length)
35
35
  if (WasmI32.eqz(WasmI32.and(length, 1n))) {
36
36
  throw Exception.InvalidArgument("Length argument must be an integer")
@@ -43,7 +43,7 @@ let initLength = (length) => {
43
43
  }
44
44
 
45
45
  /**
46
- * Returns the length of the input array.
46
+ * Provides the length of the input array.
47
47
  *
48
48
  * @param array: The array to inspect
49
49
  * @returns The number of elements in the array
@@ -51,7 +51,7 @@ let initLength = (length) => {
51
51
  * @since v0.1.0
52
52
  */
53
53
  @disableGC
54
- export let rec length = (array) => {
54
+ export let rec length = array => {
55
55
  let ptr = WasmI32.fromGrain(array: Array<a>)
56
56
  let ret = tagSimpleNumber(WasmI32.load(ptr, _ARRAY_LENGTH_OFFSET))
57
57
  Memory.decRef(ptr)
@@ -73,15 +73,23 @@ export let rec length = (array) => {
73
73
  * @since v0.1.0
74
74
  */
75
75
  @disableGC
76
- export let rec make /*: (Number, a) -> Array<a>*/ = (length: Number, item: a) => {
76
+ export let rec make /*: (Number, a) -> Array<a>*/ =
77
+ (
78
+ length: Number,
79
+ item: a,
80
+ ) => {
77
81
  let lengthArg = length
78
82
  let length = initLength(length)
79
83
  let byteLength = WasmI32.mul(length, 4n)
80
84
  let array = allocateArray(length)
81
85
  for (let mut i = 0n; WasmI32.ltS(i, byteLength); i = WasmI32.add(i, 4n)) {
82
- WasmI32.store(WasmI32.add(array, i), Memory.incRef(WasmI32.fromGrain(item)), _ARRAY_START_OFFSET)
86
+ WasmI32.store(
87
+ WasmI32.add(array, i),
88
+ Memory.incRef(WasmI32.fromGrain(item)),
89
+ _ARRAY_START_OFFSET
90
+ )
83
91
  }
84
- let ret = WasmI32.toGrain(array): (Array<a>)
92
+ let ret = WasmI32.toGrain(array): Array<a>
85
93
  Memory.decRef(WasmI32.fromGrain(lengthArg))
86
94
  Memory.decRef(WasmI32.fromGrain(item))
87
95
  Memory.decRef(WasmI32.fromGrain(make))
@@ -97,27 +105,35 @@ export let rec make /*: (Number, a) -> Array<a>*/ = (length: Number, item: a) =
97
105
  * @param fn: The initializer function to call with each index, where the value returned will be used to initialize the element
98
106
  * @returns The new array
99
107
  *
100
- * @example Array.init(5, n => n + 3) // [> 8, 9, 10, 11, 12]
108
+ * @example Array.init(5, n => n + 3) // [> 3, 4, 5, 6, 7]
101
109
  *
102
110
  * @since v0.1.0
103
111
  */
104
112
  @disableGC
105
- export let rec init /*: (Number, Number -> a) -> Array<a>*/ = (length: Number, fn: Number -> a) => {
113
+ export let rec init /*: (Number, Number -> a) -> Array<a>*/ =
114
+ (
115
+ length: Number,
116
+ fn: Number -> a,
117
+ ) => {
106
118
  let length = initLength(length)
107
119
  let byteLength = WasmI32.mul(length, 4n)
108
120
  let array = allocateArray(length)
109
121
  let mut index = 0n
110
122
  for (let mut i = 0n; WasmI32.ltS(i, byteLength); i = WasmI32.add(i, 4n)) {
111
- Memory.incRef(WasmI32.fromGrain(fn));
123
+ Memory.incRef(WasmI32.fromGrain(fn))
112
124
  // [FIXME] This line fails the array/map test suite (#815)
113
125
  //assert !WasmI32.eqz(WasmI32.and(WasmI32.fromGrain(index), 1n)) // must be a simple int for next line to be correct
114
- WasmI32.store(WasmI32.add(array, i), WasmI32.fromGrain(fn(tagSimpleNumber(index))), _ARRAY_START_OFFSET)
126
+ WasmI32.store(
127
+ WasmI32.add(array, i),
128
+ WasmI32.fromGrain(fn(tagSimpleNumber(index))),
129
+ _ARRAY_START_OFFSET
130
+ )
115
131
  //WasmI32.store(WasmI32.add(array, i), WasmI32.fromGrain(4), _ARRAY_START_OFFSET)
116
132
  index = WasmI32.add(index, 1n)
117
133
  }
118
134
  Memory.decRef(WasmI32.fromGrain(fn))
119
135
  Memory.decRef(WasmI32.fromGrain(init))
120
- WasmI32.toGrain(array): (Array<a>)
136
+ WasmI32.toGrain(array): Array<a>
121
137
  }
122
138
 
123
139
  /**
@@ -155,8 +171,8 @@ export let set = (index, value, array) => {
155
171
  }
156
172
 
157
173
  /**
158
- * Creates a new array with the items the first array, followed by
159
- * the items of the second array. This does not modify the arguments.
174
+ * Creates a new array with the elements of the first array followed by
175
+ * the elements of the second array. This does not modify the arguments.
160
176
  *
161
177
  * @param array1: The array containing elements to appear first
162
178
  * @param array2: The array containing elements to appear second
@@ -186,29 +202,29 @@ export let append = (array1, array2) => {
186
202
  *
187
203
  * @since v0.1.0
188
204
  */
189
- export let concat = (arrays) => {
205
+ export let concat = arrays => {
190
206
  // This function is slightly verbose to avoid depending on the List stdlib.
191
207
 
192
208
  let rec findLength = (arrays, acc) => {
193
209
  match (arrays) {
194
210
  [fst, ...rest] => findLength(rest, acc + length(fst)),
195
- [] => acc
211
+ [] => acc,
196
212
  }
197
213
  }
198
214
 
199
215
  let mut offset = 0
200
216
  let mut arrs = arrays
201
217
 
202
- let rec next = (index) => {
218
+ let rec next = index => {
203
219
  let array = match (arrs) {
204
220
  [fst, ..._] => fst,
205
- [] => fail "end of arrays list"
221
+ [] => fail "end of arrays list",
206
222
  }
207
223
  if (index - offset == length(array)) {
208
224
  offset += length(array)
209
225
  arrs = match (arrs) {
210
226
  [_, ...rest] => rest,
211
- [] => fail "end of arrays list"
227
+ [] => fail "end of arrays list",
212
228
  }
213
229
  next(index)
214
230
  } else {
@@ -228,7 +244,7 @@ export let concat = (arrays) => {
228
244
  *
229
245
  * @since v0.1.0
230
246
  */
231
- export let copy = (array) => {
247
+ export let copy = array => {
232
248
  init(length(array), n => array[n])
233
249
  }
234
250
 
@@ -245,7 +261,7 @@ export let cycle = (fn, n, array) => {
245
261
  let length = length(array)
246
262
  for (let mut iteration = 0; iteration < n; iteration += 1) {
247
263
  for (let mut count = 0; count < length; count += 1) {
248
- fn(array[count]): (Void)
264
+ fn(array[count]): Void
249
265
  }
250
266
  }
251
267
  }
@@ -262,12 +278,12 @@ export let cycle = (fn, n, array) => {
262
278
  export let forEach = (fn, array) => {
263
279
  let length = length(array)
264
280
  for (let mut count = 0; count < length; count += 1) {
265
- fn(array[count]): (Void)
281
+ fn(array[count]): Void
266
282
  }
267
283
  }
268
284
 
269
285
  /**
270
- * Iterates an array, calling an iterator function with each element.
286
+ * Iterates an array, calling an iterator function on each element.
271
287
  * Also passes the index as the second argument to the function.
272
288
  *
273
289
  * @param fn: The iterator function to call with each element
@@ -279,7 +295,7 @@ export let forEach = (fn, array) => {
279
295
  export let forEachi = (fn, array) => {
280
296
  let length = length(array)
281
297
  for (let mut count = 0; count < length; count += 1) {
282
- fn(array[count], count): (Void)
298
+ fn(array[count], count): Void
283
299
  }
284
300
  }
285
301
 
@@ -296,7 +312,7 @@ export let forEachi = (fn, array) => {
296
312
  */
297
313
  export let map = (fn, array) => {
298
314
  let length = length(array)
299
- init(length, (i) => {
315
+ init(length, i => {
300
316
  fn(array[i])
301
317
  })
302
318
  }
@@ -313,7 +329,7 @@ export let map = (fn, array) => {
313
329
  */
314
330
  export let mapi = (fn, array) => {
315
331
  let length = length(array)
316
- init(length, (index) => {
332
+ init(length, index => {
317
333
  fn(array[index], index)
318
334
  })
319
335
  }
@@ -338,7 +354,7 @@ export let mapi = (fn, array) => {
338
354
  */
339
355
  export let reduce = (fn, initial, array) => {
340
356
  let mut acc = initial
341
- forEach((el) => acc = fn(acc, el), array)
357
+ forEach(el => acc = fn(acc, el), array)
342
358
  acc
343
359
  }
344
360
 
@@ -387,26 +403,30 @@ export let flatMap = (fn, array) => {
387
403
  *
388
404
  * @param fn: The function to call on each element, where the returned value indicates if the element satisfies the condition
389
405
  * @param array: The array to check
390
- * @returns `true` if all elements satify the condition, otherwise `false`
406
+ * @returns `true` if all elements satify the condition or `false` otherwise
391
407
  *
392
408
  * @since v0.3.0
393
409
  */
394
410
  export let every = (fn, array) => {
395
- reduce((acc, value) => { acc && fn(value) }, true, array)
411
+ reduce((acc, value) => {
412
+ acc && fn(value)
413
+ }, true, array)
396
414
  }
397
415
 
398
416
  /**
399
417
  * Checks that the given condition is satisfied **at least
400
- * once** by an item in the input array.
418
+ * once** by an element in the input array.
401
419
  *
402
420
  * @param fn: The function to call on each element, where the returned value indicates if the element satisfies the condition
403
421
  * @param array: The array to iterate
404
- * @returns `true` if one or more elements satify the condition, otherwise `false`
422
+ * @returns `true` if one or more elements satify the condition or `false` otherwise
405
423
  *
406
424
  * @since v0.3.0
407
425
  */
408
426
  export let some = (fn, array) => {
409
- reduce((acc, value) => { acc || fn(value) }, false, array)
427
+ reduce((acc, value) => {
428
+ acc || fn(value)
429
+ }, false, array)
410
430
  }
411
431
 
412
432
  /**
@@ -467,9 +487,9 @@ export let fillRange = (value, start, stop, array) => {
467
487
  *
468
488
  * @since v0.4.0
469
489
  */
470
- export let reverse = (array) => {
490
+ export let reverse = array => {
471
491
  let len = length(array)
472
- init(len, (index) => {
492
+ init(len, index => {
473
493
  let last = len - index - 1
474
494
  array[last]
475
495
  })
@@ -483,7 +503,7 @@ export let reverse = (array) => {
483
503
  *
484
504
  * @since v0.1.0
485
505
  */
486
- export let toList = (array) => {
506
+ export let toList = array => {
487
507
  let rec buildList = (acc, index) => {
488
508
  let index = index - 1
489
509
  if (index < 0) {
@@ -503,22 +523,22 @@ export let toList = (array) => {
503
523
  *
504
524
  * @since v0.1.0
505
525
  */
506
- export let fromList = (list) => {
526
+ export let fromList = list => {
507
527
  let rec listLength = (list, acc) => {
508
528
  match (list) {
509
529
  [_, ...rest] => listLength(rest, acc + 1),
510
- [] => acc
530
+ [] => acc,
511
531
  }
512
532
  }
513
533
 
514
534
  let mut lst = list
515
- let rec next = (index) => {
535
+ let rec next = index => {
516
536
  match (lst) {
517
537
  [fst, ...rest] => {
518
538
  lst = rest
519
539
  fst
520
540
  },
521
- [] => next(index)
541
+ [] => next(index),
522
542
  }
523
543
  }
524
544
  init(listLength(list, 0), next)
@@ -529,8 +549,8 @@ export let fromList = (list) => {
529
549
  * Uses the generic `==` structural equality operator.
530
550
  *
531
551
  * @param search: The value to compare
532
- * @param array: The array to iterate
533
- * @returns `true` if the value exists in the array, otherwise `false`
552
+ * @param array: The array to inspect
553
+ * @returns `true` if the value exists in the array or `false` otherwise
534
554
  *
535
555
  * @since v0.2.0
536
556
  */
@@ -549,20 +569,20 @@ export let contains = (search, array) => {
549
569
  *
550
570
  * @param fn: The function to call on each element, where the returned value indicates if the element satisfies the condition
551
571
  * @param array: The array to search
552
- * @returns `Some(element)` containing the first value found and `None` otherwise
572
+ * @returns `Some(element)` containing the first value found or `None` otherwise
553
573
  *
554
574
  * @since v0.2.0
555
575
  */
556
576
  export let find = (fn, array) => {
557
577
  let length = length(array)
558
- if(length == 0){
578
+ if (length == 0) {
559
579
  None
560
580
  } else {
561
581
  let mut count = 0
562
582
  let mut matching = false
563
583
  let mut matchedItem = array[0]
564
584
  while (count < length) {
565
- if(fn(array[count])) {
585
+ if (fn(array[count])) {
566
586
  matching = true
567
587
  matchedItem = array[count]
568
588
  count = length
@@ -570,7 +590,7 @@ export let find = (fn, array) => {
570
590
  count += 1
571
591
  }
572
592
  }
573
- if(!matching) {
593
+ if (!matching) {
574
594
  None
575
595
  } else {
576
596
  Some(matchedItem)
@@ -583,20 +603,20 @@ export let find = (fn, array) => {
583
603
  *
584
604
  * @param fn: The function to call on each element, where the returned value indicates if the element satisfies the condition
585
605
  * @param array: The array to search
586
- * @returns `Some(index)` containing the index of the first element found and `None` otherwise
606
+ * @returns `Some(index)` containing the index of the first element found or `None` otherwise
587
607
  *
588
608
  * @since v0.2.0
589
609
  */
590
610
  export let findIndex = (fn, array) => {
591
611
  let length = length(array)
592
- if(length == 0){
612
+ if (length == 0) {
593
613
  None
594
614
  } else {
595
615
  let mut count = 0
596
616
  let mut matching = false
597
617
  let mut matchedIndex = 0
598
618
  while (count < length) {
599
- if(fn(array[count])) {
619
+ if (fn(array[count])) {
600
620
  matching = true
601
621
  matchedIndex = count
602
622
  count = length
@@ -604,7 +624,7 @@ export let findIndex = (fn, array) => {
604
624
  count += 1
605
625
  }
606
626
  }
607
- if(!matching) {
627
+ if (!matching) {
608
628
  None
609
629
  } else {
610
630
  Some(matchedIndex)
@@ -628,7 +648,7 @@ export let product = (array1: Array<a>, array2: Array<b>) => {
628
648
  let mut indexA = -1
629
649
 
630
650
  init(lenA * lenB, n => {
631
- if(n % lenB == 0){
651
+ if (n % lenB == 0) {
632
652
  indexA += 1
633
653
  } else {
634
654
  indexA = indexA
@@ -651,7 +671,7 @@ export let count = (fn, array) => {
651
671
  let mut position = 0
652
672
  let mut count = 0
653
673
  for (let mut position = 0; position < length; position += 1) {
654
- if(fn(array[position])) {
674
+ if (fn(array[position])) {
655
675
  count += 1
656
676
  }
657
677
  }
@@ -693,13 +713,13 @@ export let counti = (fn, array) => {
693
713
  export let filter = (fn, array) => {
694
714
  let filtered = copy(array)
695
715
  let mut position = 0
696
- forEach((el) => {
716
+ forEach(el => {
697
717
  if (fn(el)) {
698
718
  filtered[position] = el
699
719
  position += 1
700
720
  }
701
721
  }, array)
702
- init(position, (index) => {
722
+ init(position, index => {
703
723
  filtered[index]
704
724
  })
705
725
  }
@@ -724,7 +744,7 @@ export let filteri = (fn, array) => {
724
744
  position += 1
725
745
  }
726
746
  }, array)
727
- init(position, (index) => {
747
+ init(position, index => {
728
748
  filtered[index]
729
749
  })
730
750
  }
@@ -738,11 +758,9 @@ export let filteri = (fn, array) => {
738
758
  *
739
759
  * @since v0.3.0
740
760
  */
741
- export let unique = (array) => {
742
- filteri(
743
- (el, index) => findIndex(value => value == el, array) == Some(index),
744
- array
745
- )
761
+ export let unique = array => {
762
+ filteri((el, index) =>
763
+ findIndex(value => value == el, array) == Some(index), array)
746
764
  }
747
765
 
748
766
  /**
@@ -777,15 +795,17 @@ export let zip = (array1: Array<a>, array2: Array<b>) => {
777
795
  *
778
796
  * @since v0.4.0
779
797
  */
780
- export let unzip = (array) => {
798
+ export let unzip = array => {
781
799
  let lenArr = length(array)
782
800
 
783
801
  let a = init(lenArr, n => {
784
- let (fst, _) = array[n]; fst
802
+ let (fst, _) = array[n]
803
+ fst
785
804
  })
786
805
 
787
806
  let b = init(lenArr, n => {
788
- let (_, snd) = array[n]; snd
807
+ let (_, snd) = array[n]
808
+ snd
789
809
  })
790
810
 
791
811
  (a, b)
@@ -804,10 +824,10 @@ export let join = (separator: String, items: Array<String>) => {
804
824
  let iter = (acc, str) => {
805
825
  match (acc) {
806
826
  None => Some(str),
807
- Some(prev) => Some(prev ++ separator ++ str)
827
+ Some(prev) => Some(prev ++ separator ++ str),
808
828
  }
809
829
  }
810
- match(reduce(iter, None, items)) {
830
+ match (reduce(iter, None, items)) {
811
831
  None => "",
812
832
  Some(s) => s,
813
833
  }
@@ -850,7 +870,7 @@ export let slice = (startIndex, endIndex, array) => {
850
870
  endIndex
851
871
  }
852
872
 
853
- let newLength = endIndex - startIndex;
873
+ let newLength = endIndex - startIndex
854
874
  if (newLength < 0) {
855
875
  [>]
856
876
  } else if (newLength > arrayLength) {
@@ -872,8 +892,8 @@ export let sort = (comp, array) => {
872
892
  let partition = (low, high) => {
873
893
  let pivot = array[high]
874
894
  let mut i = low - 1
875
- for(let mut j = low; j < high; j += 1) {
876
- if(comp(array[j], pivot) < 0){
895
+ for (let mut j = low; j < high; j += 1) {
896
+ if (comp(array[j], pivot) < 0) {
877
897
  i += 1
878
898
  let temp = array[i]
879
899
  array[i] = array[j]
@@ -886,7 +906,7 @@ export let sort = (comp, array) => {
886
906
  i + 1
887
907
  }
888
908
  let rec quicksort = (low, high) => {
889
- if(low < high){
909
+ if (low < high) {
890
910
  let partitionIndex = partition(low, high)
891
911
  quicksort(partitionIndex + 1, high)
892
912
  quicksort(low, partitionIndex - 1)
@@ -897,10 +917,10 @@ export let sort = (comp, array) => {
897
917
  }
898
918
 
899
919
  /**
900
- * Rotates an array by n elements to the right, in place.
920
+ * Rotates array elements by the specified amount to the right, in place.
901
921
  *
902
- * If n is negative, the array will be rotated by n elements
903
- * to the left. See examples.
922
+ * If value is negative, array elements will be rotated by the
923
+ * specified amount to the left. See examples.
904
924
  *
905
925
  * @param n: The number of elements to rotate by
906
926
  * @param arr: The array to be rotated
@@ -913,8 +933,7 @@ export let rotate = (n, arr) => {
913
933
  let rec gcd = (a, b) => {
914
934
  if (b == 0) {
915
935
  a
916
- }
917
- else{
936
+ } else {
918
937
  gcd(b, a % b)
919
938
  }
920
939
  }
@@ -923,7 +942,7 @@ export let rotate = (n, arr) => {
923
942
  if (arrLen > 0) {
924
943
  let k = n % arrLen
925
944
  let mut d = -1
926
- let mut j = 0
945
+ let mut j = 0
927
946
  for (let mut i = 0; i < gcd(arrLen, k); i += 1) {
928
947
  j = i
929
948
  let temp = arr[i]