@grain/stdlib 0.4.0 → 0.4.4

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,70 @@
1
1
  # Changelog
2
2
 
3
+ ### [0.4.4](https://www.github.com/grain-lang/grain/compare/stdlib-v0.4.3...stdlib-v0.4.4) (2021-12-11)
4
+
5
+
6
+ ### Features
7
+
8
+ * **stdlib:** Add reverse function to String module ([#1027](https://www.github.com/grain-lang/grain/issues/1027)) ([df761db](https://www.github.com/grain-lang/grain/commit/df761db55b3e14e31190090ae008ce5047135c09))
9
+ * **stdlib:** Add rotate function in Array module ([#838](https://www.github.com/grain-lang/grain/issues/838)) ([98fc577](https://www.github.com/grain-lang/grain/commit/98fc577ee754317cd2421bfaa8e3c1e049488949))
10
+ * **stdlib:** Add sort function to Array module ([#1012](https://www.github.com/grain-lang/grain/issues/1012)) ([9091930](https://www.github.com/grain-lang/grain/commit/9091930344224925bb7b2e1ef6f879c79a5c2f62))
11
+ * **stdlib:** Implement List.sort via mergesort ([#1014](https://www.github.com/grain-lang/grain/issues/1014)) ([a076e20](https://www.github.com/grain-lang/grain/commit/a076e200013114ccf16c2e6cbe814af1ec09c1ce))
12
+ * **stdlib:** Number.parseInt ([#1051](https://www.github.com/grain-lang/grain/issues/1051)) ([abafb58](https://www.github.com/grain-lang/grain/commit/abafb587e54219a32ed77ba09863bb2d6a80bac8))
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * **graindoc:** Ensure value_description is resolved to outcome before printing ([#1070](https://www.github.com/grain-lang/grain/issues/1070)) ([5eb05cc](https://www.github.com/grain-lang/grain/commit/5eb05cc2dedc3b933e194be86dd5d3c3656d6490))
18
+ * **stdlib:** Add bounds checking to Buffer addStringSlice & addBytesSlice ([#1065](https://www.github.com/grain-lang/grain/issues/1065)) ([06fe512](https://www.github.com/grain-lang/grain/commit/06fe512e863aeeb855ccf3e3b83bcd3bc8854723))
19
+ * **stdlib:** Fix String.encode GC ([#1067](https://www.github.com/grain-lang/grain/issues/1067)) ([0ab38c9](https://www.github.com/grain-lang/grain/commit/0ab38c9f4aa0ee84688ba5c6bec1521b380d38b1))
20
+ * **stdlib:** Removed memory leak in Hash module ([#1045](https://www.github.com/grain-lang/grain/issues/1045)) ([01a81c6](https://www.github.com/grain-lang/grain/commit/01a81c6a2573cca94b2d57d0fc70693d39f810a1))
21
+ * **stdlib:** Removed memory leaks in Buffer module ([#1047](https://www.github.com/grain-lang/grain/issues/1047)) ([d33017b](https://www.github.com/grain-lang/grain/commit/d33017b37e988d3facbca2e30e3de4fb8c7b5b8a))
22
+ * **stdlib:** Support arrays of any type in Array rotate ([#1048](https://www.github.com/grain-lang/grain/issues/1048)) ([3ceb1cf](https://www.github.com/grain-lang/grain/commit/3ceb1cf04c1604f49077e8733dcccb6cdaaf9f3a))
23
+ * **stdlib:** Support empty arrays in Array rotate ([3ceb1cf](https://www.github.com/grain-lang/grain/commit/3ceb1cf04c1604f49077e8733dcccb6cdaaf9f3a))
24
+
25
+ ### [0.4.3](https://www.github.com/grain-lang/grain/compare/stdlib-v0.4.2...stdlib-v0.4.3) (2021-10-27)
26
+
27
+
28
+ ### Features
29
+
30
+ * **stdlib:** Add cycle function to Array module ([#993](https://www.github.com/grain-lang/grain/issues/993)) ([c595622](https://www.github.com/grain-lang/grain/commit/c595622b28366655dfd5447270e8f9fc3f988a67))
31
+
32
+
33
+ ### Bug Fixes
34
+
35
+ * **compiler:** Ensure TExpApp is always expansive in Grain ([ef0a69f](https://www.github.com/grain-lang/grain/commit/ef0a69fb4418d318b3227e5db7e743a026762274))
36
+ * **compiler:** Handle let-mut value restriction, such that mutable lets are always expansive ([ef0a69f](https://www.github.com/grain-lang/grain/commit/ef0a69fb4418d318b3227e5db7e743a026762274))
37
+ * **compiler:** Properly handle value restriction on function application & mutable vars ([#988](https://www.github.com/grain-lang/grain/issues/988)) ([ef0a69f](https://www.github.com/grain-lang/grain/commit/ef0a69fb4418d318b3227e5db7e743a026762274))
38
+ * **runtime:** Add types to boxed GC functions to avoid weak type errors ([ef0a69f](https://www.github.com/grain-lang/grain/commit/ef0a69fb4418d318b3227e5db7e743a026762274))
39
+ * **stdlib:** Fixed memory leak in String.explode ([#1001](https://www.github.com/grain-lang/grain/issues/1001)) ([c479a05](https://www.github.com/grain-lang/grain/commit/c479a05f48abcc4c9e98d5cf0ba698230d41031b))
40
+
41
+ ### [0.4.2](https://www.github.com/grain-lang/grain/compare/stdlib-v0.4.1...stdlib-v0.4.2) (2021-10-11)
42
+
43
+
44
+ ### Features
45
+
46
+ * **compiler:** Inline not `(!)` operator ([#937](https://www.github.com/grain-lang/grain/issues/937)) ([3f5e9a9](https://www.github.com/grain-lang/grain/commit/3f5e9a962ec8565f4fb79a1ee36d7b492da5cf11))
47
+ * **stdlib:** Add Conv.wasmI32ToNumber function ([#978](https://www.github.com/grain-lang/grain/issues/978)) ([c93ade8](https://www.github.com/grain-lang/grain/commit/c93ade873b51acca556e19a7483a5f29b4b6caa9))
48
+ * **stdlib:** Add string trim functions to String module ([#951](https://www.github.com/grain-lang/grain/issues/951)) ([e55de8f](https://www.github.com/grain-lang/grain/commit/e55de8fc0335b45252da9741a80b46a702cdb5b6))
49
+ * **stdlib:** Regular Expressions ([#680](https://www.github.com/grain-lang/grain/issues/680)) ([9601e16](https://www.github.com/grain-lang/grain/commit/9601e1655f1ffc76b700efef317366457c5614ef))
50
+
51
+
52
+ ### Bug Fixes
53
+
54
+ * **stdlib:** Fix Char.code memory issue ([#928](https://www.github.com/grain-lang/grain/issues/928)) ([dfa31d8](https://www.github.com/grain-lang/grain/commit/dfa31d8aa60a41d08494f3817bdb628a30d83f41))
55
+ * **stdlib:** Fix issue with list printing ([#894](https://www.github.com/grain-lang/grain/issues/894)) ([e2a33a9](https://www.github.com/grain-lang/grain/commit/e2a33a9607bd076abbf6375389f1a7896775e6bc))
56
+ * **stdlib:** Fix memory issue in list printing ([#912](https://www.github.com/grain-lang/grain/issues/912)) ([3e0a805](https://www.github.com/grain-lang/grain/commit/3e0a8059a36d1042fa06d6aed54565ced116fd87))
57
+ * **stdlib:** Fix memory leaks in Char stdlib ([#929](https://www.github.com/grain-lang/grain/issues/929)) ([99cc94b](https://www.github.com/grain-lang/grain/commit/99cc94b3e2010c7fa6b2c244758dbbe13e43f903))
58
+
59
+ ### [0.4.1](https://www.github.com/grain-lang/grain/compare/stdlib-v0.4.0...stdlib-v0.4.1) (2021-09-07)
60
+
61
+
62
+ ### Bug Fixes
63
+
64
+ * **stdlib:** Annotate generic types in Buffer ([#876](https://www.github.com/grain-lang/grain/issues/876)) ([ad46b9e](https://www.github.com/grain-lang/grain/commit/ad46b9e6b0d2d9d562b56e5cbf1ae6751028d93a))
65
+ * **stdlib:** Correct fdPwrite return value ([#875](https://www.github.com/grain-lang/grain/issues/875)) ([ceaf6af](https://www.github.com/grain-lang/grain/commit/ceaf6af52889f5d7c8a16df9a5a9ae5ff6752105))
66
+ * **stdlib:** Correct type signatures on some Array functions ([#880](https://www.github.com/grain-lang/grain/issues/880)) ([04bf4d3](https://www.github.com/grain-lang/grain/commit/04bf4d3066cf80de8cb3da834124e29558c6d21a))
67
+
3
68
  ## [0.4.0](https://www.github.com/grain-lang/grain/compare/stdlib-v0.3.2...stdlib-v0.4.0) (2021-09-06)
4
69
 
5
70
 
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017-2021 Oscar Spencer <oscar@grain-lang.org> and Philip Blair <philip@grain-lang.org>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # @grain/stdlib
2
+
3
+ The standard library for the Grain language.
4
+
5
+ ## Why
6
+
7
+ This package provides a distributable copy of the Grain standard library. Currently, it is available through npm.
8
+
9
+ ## Installation
10
+
11
+ Usually, you won't need to install this package. However, if you need it, install it with npm:
12
+
13
+ ```sh
14
+ npm install @grain/stdlib
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ Grain programs will search for an imported module in the `stdlib` if not available in your other search paths.
20
+
21
+ For example, you can import the `number` stdlib:
22
+
23
+ ```grain
24
+ import Number from "number"
25
+ Number.abs(-1)
26
+ ```
27
+
28
+ ## API
29
+
30
+ This package includes generated markdown documentation, but we recommend using our API docs on [grain-lang.org](https://grain-lang.org/docs/stdlib/pervasives).
31
+
32
+ ## License
33
+
34
+ MIT
package/array.gr CHANGED
@@ -232,6 +232,24 @@ export let copy = (array) => {
232
232
  init(length(array), n => array[n])
233
233
  }
234
234
 
235
+ /**
236
+ * Iterates an array a given number of times, calling an iterator function on each element.
237
+ *
238
+ * @param fn: The iterator function to call with each element
239
+ * @param n: The number of times to iterate the given array
240
+ * @param array: The array to iterate
241
+ *
242
+ * @since v0.4.4
243
+ */
244
+ export let cycle = (fn, n, array) => {
245
+ let length = length(array)
246
+ for (let mut iteration = 0; iteration < n; iteration += 1) {
247
+ for (let mut count = 0; count < length; count += 1) {
248
+ fn(array[count]): (Void)
249
+ }
250
+ }
251
+ }
252
+
235
253
  /**
236
254
  * Iterates an array, calling an iterator function on each element.
237
255
  *
@@ -243,10 +261,8 @@ export let copy = (array) => {
243
261
  */
244
262
  export let forEach = (fn, array) => {
245
263
  let length = length(array)
246
- let mut count = 0
247
- while (count < length) {
248
- fn(array[count])
249
- count = incr(count)
264
+ for (let mut count = 0; count < length; count += 1) {
265
+ fn(array[count]): (Void)
250
266
  }
251
267
  }
252
268
 
@@ -262,10 +278,8 @@ export let forEach = (fn, array) => {
262
278
  */
263
279
  export let forEachi = (fn, array) => {
264
280
  let length = length(array)
265
- let mut count = 0
266
- while (count < length) {
267
- fn(array[count], count)
268
- count = incr(count)
281
+ for (let mut count = 0; count < length; count += 1) {
282
+ fn(array[count], count): (Void)
269
283
  }
270
284
  }
271
285
 
@@ -435,9 +449,12 @@ export let fillRange = (value, start, stop, array) => {
435
449
  }
436
450
 
437
451
  let mut index = startIndex
438
- while (index < stopIndex && index < length) {
439
- array[index] = value
452
+ for (
453
+ let mut index = startIndex;
454
+ index < stopIndex && index < length;
440
455
  index += 1
456
+ ) {
457
+ array[index] = value
441
458
  }
442
459
  void
443
460
  }
@@ -520,11 +537,9 @@ export let fromList = (list) => {
520
537
  export let contains = (search, array) => {
521
538
  // TODO: This should use recursion when we can pattern match arrays
522
539
  let len = length(array)
523
- let mut index = 0
524
540
  let mut found = false
525
- while ((!found) && (index < len)) {
526
- found = (array[index] == search)
527
- index += 1
541
+ for (let mut index = 0; !found && index < len; index += 1) {
542
+ found = array[index] == search
528
543
  }
529
544
  found
530
545
  }
@@ -552,7 +567,7 @@ export let find = (fn, array) => {
552
567
  matchedItem = array[count]
553
568
  count = length
554
569
  } else {
555
- count = incr(count)
570
+ count += 1
556
571
  }
557
572
  }
558
573
  if(!matching) {
@@ -586,7 +601,7 @@ export let findIndex = (fn, array) => {
586
601
  matchedIndex = count
587
602
  count = length
588
603
  } else {
589
- count = incr(count)
604
+ count += 1
590
605
  }
591
606
  }
592
607
  if(!matching) {
@@ -607,14 +622,14 @@ export let findIndex = (fn, array) => {
607
622
  *
608
623
  * @since v0.2.0
609
624
  */
610
- export let product = (array1, array2) => {
625
+ export let product = (array1: Array<a>, array2: Array<b>) => {
611
626
  let lenA = length(array1)
612
627
  let lenB = length(array2)
613
628
  let mut indexA = -1
614
629
 
615
630
  init(lenA * lenB, n => {
616
631
  if(n % lenB == 0){
617
- indexA = incr(indexA)
632
+ indexA += 1
618
633
  } else {
619
634
  indexA = indexA
620
635
  }
@@ -635,12 +650,9 @@ export let count = (fn, array) => {
635
650
  let length = length(array)
636
651
  let mut position = 0
637
652
  let mut count = 0
638
- while (position < length) {
653
+ for (let mut position = 0; position < length; position += 1) {
639
654
  if(fn(array[position])) {
640
- count = incr(count)
641
- position = incr(position)
642
- } else {
643
- position = incr(position)
655
+ count += 1
644
656
  }
645
657
  }
646
658
  count
@@ -658,14 +670,10 @@ export let count = (fn, array) => {
658
670
  */
659
671
  export let counti = (fn, array) => {
660
672
  let length = length(array)
661
- let mut position = 0
662
673
  let mut count = 0
663
- while (position < length) {
664
- if(fn(array[position], position)) {
665
- count = incr(count)
666
- position = incr(position)
667
- } else {
668
- position = incr(position)
674
+ for (let mut position = 0; position < length; position += 1) {
675
+ if (fn(array[position], position)) {
676
+ count += 1
669
677
  }
670
678
  }
671
679
  count
@@ -688,7 +696,7 @@ export let filter = (fn, array) => {
688
696
  forEach((el) => {
689
697
  if (fn(el)) {
690
698
  filtered[position] = el
691
- position = incr(position)
699
+ position += 1
692
700
  }
693
701
  }, array)
694
702
  init(position, (index) => {
@@ -713,7 +721,7 @@ export let filteri = (fn, array) => {
713
721
  forEachi((el, index) => {
714
722
  if (fn(el, index)) {
715
723
  filtered[position] = el
716
- position = incr(position)
724
+ position += 1
717
725
  }
718
726
  }, array)
719
727
  init(position, (index) => {
@@ -750,7 +758,7 @@ export let unique = (array) => {
750
758
  *
751
759
  * @since v0.4.0
752
760
  */
753
- export let zip = (array1, array2) => {
761
+ export let zip = (array1: Array<a>, array2: Array<b>) => {
754
762
  let len = length(array1)
755
763
  if (len != length(array2)) {
756
764
  fail "arguments to zip must be same length"
@@ -805,6 +813,18 @@ export let join = (separator: String, items: Array<String>) => {
805
813
  }
806
814
  }
807
815
 
816
+ /**
817
+ * A simple helper function to convert a negative array index
818
+ * number to its positive positional equivalent.
819
+ */
820
+ let wrapNegativeIndex = (arrLen, idx) => {
821
+ if (idx >= 0) {
822
+ idx
823
+ } else {
824
+ arrLen + idx
825
+ }
826
+ }
827
+
808
828
  /**
809
829
  * Slices an array given zero-based start and end indexes. The value
810
830
  * at the end index will not be included in the result.
@@ -821,17 +841,8 @@ export let join = (separator: String, items: Array<String>) => {
821
841
  */
822
842
  export let slice = (startIndex, endIndex, array) => {
823
843
  let arrayLength = length(array)
824
-
825
- let wrapNegativeIndex = idx => {
826
- if (idx >= 0) {
827
- idx
828
- } else {
829
- arrayLength + idx
830
- }
831
- }
832
-
833
- let startIndex = wrapNegativeIndex(startIndex)
834
- let endIndex = wrapNegativeIndex(endIndex)
844
+ let startIndex = wrapNegativeIndex(arrayLength, startIndex)
845
+ let endIndex = wrapNegativeIndex(arrayLength, endIndex)
835
846
  // Ensure we aren't working with an `end` value that is too big
836
847
  let endIndex = if (endIndex > arrayLength) {
837
848
  arrayLength
@@ -848,3 +859,84 @@ export let slice = (startIndex, endIndex, array) => {
848
859
  init(newLength, n => array[startIndex + n])
849
860
  }
850
861
  }
862
+
863
+ /**
864
+ * Sorts an array in-place.
865
+ *
866
+ * Ordering is calculated using a comparator function which takes two array elements and must return 0 if both are equal, a positive number if the first is greater, and a negative number if the first is smaller.
867
+ * @param comp: The comparator function used to indicate sort order
868
+ * @param array: The array to be sorted
869
+ * @since v0.4.5
870
+ */
871
+ export let sort = (comp, array) => {
872
+ let partition = (low, high) => {
873
+ let pivot = array[high]
874
+ let mut i = low - 1
875
+ for(let mut j = low; j < high; j += 1) {
876
+ if(comp(array[j], pivot) < 0){
877
+ i += 1
878
+ let temp = array[i]
879
+ array[i] = array[j]
880
+ array[j] = temp
881
+ }
882
+ }
883
+ let temp = array[i + 1]
884
+ array[i + 1] = array[high]
885
+ array[high] = temp
886
+ i + 1
887
+ }
888
+ let rec quicksort = (low, high) => {
889
+ if(low < high){
890
+ let partitionIndex = partition(low, high)
891
+ quicksort(partitionIndex + 1, high)
892
+ quicksort(low, partitionIndex - 1)
893
+ }
894
+ }
895
+ let len = length(array)
896
+ quicksort(0, len - 1)
897
+ }
898
+
899
+ /**
900
+ * Rotates an array by n elements to the right, in place.
901
+ *
902
+ * If n is negative, the array will be rotated by n elements
903
+ * to the left. See examples.
904
+ *
905
+ * @param n: The number of elements to rotate by
906
+ * @param arr: The array to be rotated
907
+ *
908
+ * @example let array = [> 1, 2, 3, 4, 5]; rotate(2, arr); arr == [> 4, 5, 1, 2, 3]
909
+ * @example let array = [> 1, 2, 3, 4, 5]; rotate(-1, arr); arr == [> 2, 3, 4, 5, 1]
910
+ * @since v0.4.5
911
+ */
912
+ export let rotate = (n, arr) => {
913
+ let rec gcd = (a, b) => {
914
+ if (b == 0) {
915
+ a
916
+ }
917
+ else{
918
+ gcd(b, a % b)
919
+ }
920
+ }
921
+
922
+ let arrLen = length(arr)
923
+ if (arrLen > 0) {
924
+ let k = n % arrLen
925
+ let mut d = -1
926
+ let mut j = 0
927
+ for (let mut i = 0; i < gcd(arrLen, k); i += 1) {
928
+ j = i
929
+ let temp = arr[i]
930
+ while (true) {
931
+ d = (j - k) % arrLen
932
+ if (d == i) {
933
+ break
934
+ }
935
+ let newVal = arr[d]
936
+ arr[j] = newVal
937
+ j = d
938
+ }
939
+ arr[j] = temp
940
+ }
941
+ }
942
+ }
package/array.md CHANGED
@@ -48,7 +48,7 @@ Returns:
48
48
 
49
49
  |type|description|
50
50
  |----|-----------|
51
- |`Number`|The amount of elements in the array|
51
+ |`Number`|The number of elements in the array|
52
52
 
53
53
  ### Array.**make**
54
54
 
@@ -263,6 +263,27 @@ Returns:
263
263
  |----|-----------|
264
264
  |`Array<a>`|The new array containing the elements from the input|
265
265
 
266
+ ### Array.**cycle**
267
+
268
+ <details disabled>
269
+ <summary tabindex="-1">Added in <code>next</code></summary>
270
+ No other changes yet.
271
+ </details>
272
+
273
+ ```grain
274
+ cycle : ((a -> Void), Number, Array<a>) -> Void
275
+ ```
276
+
277
+ Iterates an array a given number of times, calling an iterator function on each element.
278
+
279
+ Parameters:
280
+
281
+ |param|type|description|
282
+ |-----|----|-----------|
283
+ |`fn`|`a -> Void`|The iterator function to call with each element|
284
+ |`n`|`Number`|The number of times to iterate the given array|
285
+ |`array`|`Array<a>`|The array to iterate|
286
+
266
287
  ### Array.**forEach**
267
288
 
268
289
  <details>
@@ -278,7 +299,7 @@ Returns:
278
299
  </details>
279
300
 
280
301
  ```grain
281
- forEach : ((a -> b), Array<a>) -> Void
302
+ forEach : ((a -> Void), Array<a>) -> Void
282
303
  ```
283
304
 
284
305
  Iterates an array, calling an iterator function on each element.
@@ -287,7 +308,7 @@ Parameters:
287
308
 
288
309
  |param|type|description|
289
310
  |-----|----|-----------|
290
- |`fn`|`a -> b`|The iterator function to call with each element|
311
+ |`fn`|`a -> Void`|The iterator function to call with each element|
291
312
  |`array`|`Array<a>`|The array to iterate|
292
313
 
293
314
  ### Array.**forEachi**
@@ -305,7 +326,7 @@ Parameters:
305
326
  </details>
306
327
 
307
328
  ```grain
308
- forEachi : (((a, Number) -> b), Array<a>) -> Void
329
+ forEachi : (((a, Number) -> Void), Array<a>) -> Void
309
330
  ```
310
331
 
311
332
  Iterates an array, calling an iterator function with each element.
@@ -315,7 +336,7 @@ Parameters:
315
336
 
316
337
  |param|type|description|
317
338
  |-----|----|-----------|
318
- |`fn`|`(a, Number) -> b`|The iterator function to call with each element|
339
+ |`fn`|`(a, Number) -> Void`|The iterator function to call with each element|
319
340
  |`array`|`Array<a>`|The array to iterate|
320
341
 
321
342
  ### Array.**map**
@@ -350,7 +371,7 @@ Returns:
350
371
 
351
372
  |type|description|
352
373
  |----|-----------|
353
- |`Array<a>`|The new array with mapped values|
374
+ |`Array<b>`|The new array with mapped values|
354
375
 
355
376
  ### Array.**mapi**
356
377
 
@@ -377,7 +398,7 @@ Returns:
377
398
 
378
399
  |type|description|
379
400
  |----|-----------|
380
- |`Array<a>`|The new array with mapped values|
401
+ |`Array<b>`|The new array with mapped values|
381
402
 
382
403
  ### Array.**reduce**
383
404
 
@@ -404,7 +425,7 @@ Parameters:
404
425
  |-----|----|-----------|
405
426
  |`fn`|`(a, b) -> a`|The reducer function to call on each element, where the value returned will be the next accumulator value|
406
427
  |`initial`|`a`|The initial value to use for the accumulator on the first iteration|
407
- |`array`|`Array<a>`|The array to iterate|
428
+ |`array`|`Array<b>`|The array to iterate|
408
429
 
409
430
  Returns:
410
431
 
@@ -444,7 +465,7 @@ Parameters:
444
465
  |-----|----|-----------|
445
466
  |`fn`|`(a, b, Number) -> a`|The reducer function to call on each element, where the value returned will be the next accumulator value|
446
467
  |`initial`|`a`|The initial value to use for the accumulator on the first iteration|
447
- |`array`|`Array<a>`|The array to iterate|
468
+ |`array`|`Array<b>`|The array to iterate|
448
469
 
449
470
  Returns:
450
471
 
@@ -479,7 +500,7 @@ Returns:
479
500
 
480
501
  |type|description|
481
502
  |----|-----------|
482
- |`Array<a>`|The new array|
503
+ |`Array<b>`|The new array|
483
504
 
484
505
  ### Array.**every**
485
506
 
@@ -581,7 +602,7 @@ Parameters:
581
602
  ### Array.**reverse**
582
603
 
583
604
  <details disabled>
584
- <summary tabindex="-1">Added in <code>next</code></summary>
605
+ <summary tabindex="-1">Added in <code>0.4.0</code></summary>
585
606
  No other changes yet.
586
607
  </details>
587
608
 
@@ -740,7 +761,7 @@ No other changes yet.
740
761
  </details>
741
762
 
742
763
  ```grain
743
- product : (Array<a>, Array<a0>) -> Array<(a, a0)>
764
+ product : (Array<a>, Array<b>) -> Array<(a, b)>
744
765
  ```
745
766
 
746
767
  Combines two arrays into a Cartesian product of tuples containing
@@ -751,13 +772,13 @@ Parameters:
751
772
  |param|type|description|
752
773
  |-----|----|-----------|
753
774
  |`array1`|`Array<a>`|The array to provide values for the first tuple element|
754
- |`array2`|`Array<a>`|The array to provide values for the second tuple element|
775
+ |`array2`|`Array<b>`|The array to provide values for the second tuple element|
755
776
 
756
777
  Returns:
757
778
 
758
779
  |type|description|
759
780
  |----|-----------|
760
- |`Array<(a, a0)>`|The new array containing all pairs of `(a, b)`|
781
+ |`Array<(a, b)>`|The new array containing all pairs of `(a, b)`|
761
782
 
762
783
  ### Array.**count**
763
784
 
@@ -897,12 +918,12 @@ Returns:
897
918
  ### Array.**zip**
898
919
 
899
920
  <details disabled>
900
- <summary tabindex="-1">Added in <code>next</code></summary>
921
+ <summary tabindex="-1">Added in <code>0.4.0</code></summary>
901
922
  No other changes yet.
902
923
  </details>
903
924
 
904
925
  ```grain
905
- zip : (Array<a>, Array<a0>) -> Array<(a, a0)>
926
+ zip : (Array<a>, Array<b>) -> Array<(a, b)>
906
927
  ```
907
928
 
908
929
  Produces a new array filled with tuples of elements from both given arrays.
@@ -916,18 +937,18 @@ Parameters:
916
937
  |param|type|description|
917
938
  |-----|----|-----------|
918
939
  |`array1`|`Array<a>`|The array to provide values for the first tuple element|
919
- |`array2`|`Array<a>`|The array to provide values for the second tuple element|
940
+ |`array2`|`Array<b>`|The array to provide values for the second tuple element|
920
941
 
921
942
  Returns:
922
943
 
923
944
  |type|description|
924
945
  |----|-----------|
925
- |`Array<(a, a0)>`|The new array containing indexed pairs of `(a, b)`|
946
+ |`Array<(a, b)>`|The new array containing indexed pairs of `(a, b)`|
926
947
 
927
948
  ### Array.**unzip**
928
949
 
929
950
  <details disabled>
930
- <summary tabindex="-1">Added in <code>next</code></summary>
951
+ <summary tabindex="-1">Added in <code>0.4.0</code></summary>
931
952
  No other changes yet.
932
953
  </details>
933
954
 
@@ -952,7 +973,7 @@ Returns:
952
973
  ### Array.**join**
953
974
 
954
975
  <details disabled>
955
- <summary tabindex="-1">Added in <code>next</code></summary>
976
+ <summary tabindex="-1">Added in <code>0.4.0</code></summary>
956
977
  No other changes yet.
957
978
  </details>
958
979
 
@@ -978,7 +999,7 @@ Returns:
978
999
  ### Array.**slice**
979
1000
 
980
1001
  <details disabled>
981
- <summary tabindex="-1">Added in <code>next</code></summary>
1002
+ <summary tabindex="-1">Added in <code>0.4.0</code></summary>
982
1003
  No other changes yet.
983
1004
  </details>
984
1005
 
@@ -1006,3 +1027,58 @@ Returns:
1006
1027
  |----|-----------|
1007
1028
  |`Array<a>`|The subset of the array that was sliced|
1008
1029
 
1030
+ ### Array.**sort**
1031
+
1032
+ <details disabled>
1033
+ <summary tabindex="-1">Added in <code>next</code></summary>
1034
+ No other changes yet.
1035
+ </details>
1036
+
1037
+ ```grain
1038
+ sort : (((a, a) -> Number), Array<a>) -> Void
1039
+ ```
1040
+
1041
+ Sorts an array in-place.
1042
+
1043
+ Ordering is calculated using a comparator function which takes two array elements and must return 0 if both are equal, a positive number if the first is greater, and a negative number if the first is smaller.
1044
+
1045
+ Parameters:
1046
+
1047
+ |param|type|description|
1048
+ |-----|----|-----------|
1049
+ |`comp`|`(a, a) -> Number`|The comparator function used to indicate sort order|
1050
+ |`array`|`Array<a>`|The array to be sorted|
1051
+
1052
+ ### Array.**rotate**
1053
+
1054
+ <details disabled>
1055
+ <summary tabindex="-1">Added in <code>next</code></summary>
1056
+ No other changes yet.
1057
+ </details>
1058
+
1059
+ ```grain
1060
+ rotate : (Number, Array<a>) -> Void
1061
+ ```
1062
+
1063
+ Rotates an array by n elements to the right, in place.
1064
+
1065
+ If n is negative, the array will be rotated by n elements
1066
+ to the left. See examples.
1067
+
1068
+ Parameters:
1069
+
1070
+ |param|type|description|
1071
+ |-----|----|-----------|
1072
+ |`n`|`Number`|The number of elements to rotate by|
1073
+ |`arr`|`Array<a>`|The array to be rotated|
1074
+
1075
+ Examples:
1076
+
1077
+ ```grain
1078
+ let array = [> 1, 2, 3, 4, 5]; rotate(2, arr); arr == [> 4, 5, 1, 2, 3]
1079
+ ```
1080
+
1081
+ ```grain
1082
+ let array = [> 1, 2, 3, 4, 5]; rotate(-1, arr); arr == [> 2, 3, 4, 5, 1]
1083
+ ```
1084
+