@@ -8,12 +8,36 @@ use cases. This module is useful when integrating with JavaScript libraries
8
8
which use arrays, but immutable arrays are not a practical data structure
9
9
for many use cases due to their poor asymptotics.
10
10
11
+ In addition to the functions in this module, Arrays have a number of
12
+ useful instances:
13
+
14
+ * ` Functor ` , which provides `map :: forall a b. (a -> b) -> Array a ->
15
+ Array b`
16
+ * ` Apply ` , which provides `(<* >) :: forall a b. Array (a -> b) -> Array a
17
+ -> Array b`. This function works a bit like a Cartesian product; the
18
+ result array is constructed by applying each function in the first
19
+ array to each value in the second, so that the result array ends up with
20
+ a length equal to the product of the two arguments' lengths.
21
+ * ` Bind ` , which provides `(>>=) :: forall a b. (a -> Array b) -> Array a
22
+ -> Array b` (this is the same as ` concatMap`).
23
+ * ` Semigroup ` , which provides `(<>) :: forall a. Array a -> Array a ->
24
+ Array a`, for concatenating arrays.
25
+ * ` Foldable ` , which provides a slew of functions for * folding* (also known
26
+ as * reducing* ) arrays down to one value. For example,
27
+ ` Data.Foldable.any ` tests whether an array of ` Boolean ` values contains
28
+ at least one ` true ` .
29
+ * ` Traversable ` , which provides the PureScript version of a for-loop,
30
+ allowing you to iterate over an array and accumulate effects.
31
+
32
+
11
33
#### ` singleton `
12
34
13
35
``` purescript
14
36
singleton :: forall a. a -> Array a
15
37
```
16
38
39
+ Create an array of one element
40
+
17
41
#### ` range `
18
42
19
43
``` purescript
@@ -453,7 +477,7 @@ specified equivalence relation to detemine equality.
453
477
nub :: forall a. (Eq a) => Array a -> Array a
454
478
```
455
479
456
- Special case of ` nubBy ` : ` nubBy eq `
480
+ Remove the duplicates from an array, creating a new array.
457
481
458
482
#### ` nubBy `
459
483
@@ -462,8 +486,7 @@ nubBy :: forall a. (a -> a -> Boolean) -> Array a -> Array a
462
486
```
463
487
464
488
Remove the duplicates from an array, where element equality is determined
465
- by the specified equivalence relation, creating a new array. The first
466
- occurence of an element is always the one that is kept.
489
+ by the specified equivalence relation, creating a new array.
467
490
468
491
#### ` union `
469
492
@@ -537,6 +560,17 @@ relation to compare elements, creating a new array.
537
560
zipWith :: forall a b c. (a -> b -> c) -> Array a -> Array b -> Array c
538
561
```
539
562
563
+ Apply a function to pairs of elements at the same index in two arrays,
564
+ collecting the results in a new array.
565
+
566
+ If one array is longer, elements will be discarded from the longer array.
567
+
568
+ For example
569
+
570
+ ``` purescript
571
+ zipWith (*) [1, 2, 3] [4, 5, 6, 7] == [4, 10, 18]
572
+ ```
573
+
540
574
#### ` zipWithA `
541
575
542
576
``` purescript
@@ -569,3 +603,7 @@ second components.
569
603
``` purescript
570
604
foldM :: forall m a b. (Monad m) => (a -> b -> m a) -> a -> Array b -> m a
571
605
```
606
+
607
+ Perform a fold using a monadic step function.
608
+
609
+
0 commit comments