@@ -68,100 +68,183 @@ compose(
68
68
69
69
## Api
70
70
### compose :: ` ((e -> f), ..., (b -> c), (a -> b)) -> a -> f `
71
+
71
72
Evaluates the provided functions, right to left, passing the return value
72
73
of each function to the next in line.
73
74
The initial function is passed the initial value provided to comopse.
74
75
The output of the final function, in this case ` (e->f) ` , is returned.
76
+
77
+ ``` js
78
+ compose (
79
+ map (x => x + 1 ),
80
+ map (x => x + 1 ),
81
+ map (x => x + 1 )
82
+ )([0 ]) // => 3
83
+ ```
75
84
### concat :: ` [a] -> ([a], ..., [a]) -> [a] `
76
85
Concatenates two arrays
86
+
77
87
``` js
78
- concat ([4 , 5 ])([1 ,2 ,3 ]) // => [1, 2, 3, 4, 5]
88
+ concat ([4 , 5 ])([1 ,2 ,3 ]) // => [1, 2, 3, 4, 5]
79
89
concat ([4 , 5 ])([1 ,2 ], [3 ]) // => [1, 2, 3, 4, 5]
80
90
```
81
91
> See [ Array.concat (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat )
82
92
83
93
### copyWithin :: ` (Int, Int, Int) -> [a] -> [a] `
84
94
Makes a shallow copy of part of an array and overwrites another location in the same with the copy. Size is kept constant.
85
95
96
+ ``` js
97
+ const arr = [1 , 2 , 3 , 4 , 5 ]
98
+ copyWithin (3 , 1 )(arr) // => [1, 2, 3, 2, 3]
99
+ copyWithin (3 , 1 , 2 )(arr) // => [1, 2, 3, 2, 5]
100
+ ```
86
101
> See [ Array.copyWithin (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin )
87
102
88
103
### entries:: ` [a] -> [b] `
89
104
Return an iterator over key, value pairs from the array.
90
105
106
+ ``` js
107
+ const iterator = entries ([1 , 2 , 3 , 4 , 5 ])
108
+ iterator .next ()) // => { value: [0, 1], done: false }
109
+ ```
91
110
> See [ Array.entries (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries )
92
111
93
112
### every :: ` ((a, Int, [a]) -> Boolean) -> [a] -> Boolean `
94
113
Applies predicate to all elements in array and returns false if any fail. The predicate function must at least take one parameter for each element but may optionally take an index and the entire array as 2nd and 3rd parameters, respectively.
95
114
115
+ ``` js
116
+ const predicate = x => x < 4
117
+ every (predicate)([1 , 2 , 3 ]) // => true
118
+ every (predicate)([1 , 2 , 3 , 4 , 5 ]) // => false
119
+ ```
96
120
> See [ Array.every (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every )
97
121
98
122
### fill :: ` (a, Int, Int) -> [a] -> [a] `
99
123
Fills a portion of the given array putting the same new value into each slot.
100
124
125
+ ``` js
126
+ const arr = [1 , 2 , 3 , 4 , 5 ]
127
+ fill (1 )(arr) // => [1, 1, 1, 1, 1]
128
+ fill (1 , 2 , 4 )(arr) // => [1, 2, 1, 1, 5]
129
+ ```
101
130
> See [ Array.fill (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill )
102
131
103
132
### filter :: ` ((a, Int, [a]) -> Boolean) -> [a] -> [a] `
104
133
Returns a new array containing only those elements of the given array that pass the given predicate.
105
134
135
+ ``` js
136
+ const predicate = x => x < 3
137
+ filter (predicate)([1 , 2 , 3 , 4 , 5 ]) // => [1, 2]
138
+ ```
106
139
> See [ Array.filter (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter )
107
140
108
141
### find :: ` (a -> Boolean) -> [a] -> a | undefined `
109
142
Finds and returns the first element in the given array that matches the given predicate. If no element passes, undefined is returned.
110
143
144
+ ``` js
145
+ const predicate = x => x === 3
146
+ find (predicate)([1 , 2 , 3 ]) // => 3
147
+ find (predicate)([1 , 2 ]) // => undefined
148
+ ```
111
149
> See [ Array.find (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find )
112
150
113
151
### findIndex :: ` (a -> Boolean) -> [a] -> Int `
114
152
Returns the index of the first element in the given array that matches the given predicate. If no element passes, -1 is returned.
115
153
154
+ ``` js
155
+ const arr = [1 , 2 , 3 , 4 , 5 ]
156
+ const findIndex = x => x === 3
157
+ find (x => x > 3 )(arr) // => 3
158
+ find (x => x > 80 )(arr]) // => -1
159
+ ```
116
160
> See [ Array.findIndex (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex )
117
161
118
162
### includes :: ` a -> [a] -> Boolean `
119
163
Returns true if the given element is in the given array, otherwise false.
120
164
165
+ ``` js
166
+ const animals = [' dog' , ' cat' , ' ferret' , ' hamster' ]
167
+ const hasCat = includes (' cat' )
168
+ const hasUnicorn = includes (' unicorn' )
169
+
170
+ hasCat (animals) // true
171
+ hasUnicorn (animals) // false
172
+ ```
121
173
> See [ Array.includes (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes )
122
174
123
175
### indexOf :: ` (a, Int) -> [a] -> Int `
124
176
Returns the index of the given element if it is in the given array, otherwise -1.
125
177
The 2nd parameter can be used to change where it starts looking.
126
178
179
+ ``` js
180
+ indexOf (3 )([1 , 2 , 3 , 4 , 5 ]) // => 2
181
+ indexOf (3 , 3 )([[1 , 2 , 3 , 4 , 5 , 3 ]) // => 3
182
+ ```
127
183
> See [ Array.indexOf (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf )
128
184
129
185
### join :: ` String -> [a] -> String `
130
186
Converts each element of the array to a string and concatenates them together with the given string as a delimiter.
131
187
188
+ ``` js
189
+ join (' -' )([1 , 2 , 3 ]) // => '1-2-3'
190
+ ```
132
191
> See [ Array.join (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join )
133
192
134
193
### keys :: ` [a] -> [Int] `
135
194
Return an iterator over keys from the array.
136
195
196
+ ``` js
197
+ const iterator = keys ([1 , 2 , 3 , 4 , 5 ])
198
+ iterator .next () // => { value: 0, done: false }
199
+ ```
137
200
> See [ Array.keys (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys )
138
201
139
202
### lastIndexOf :: ` (a, Int) -> [a] -> Int `
140
203
Works like indexOf but starts at the end and works backwards.
141
204
The 2nd parameter can be used to tell it where to start working backwards from.
142
205
206
+ ``` js
207
+ lastIndexOf (1 )([1 , 2 , 3 , 1 ]) // => 3
208
+ lastIndexOf (1 , - 2 )([1 , 2 , 3 , 1 ]) // => 0
209
+ ```
143
210
> See [ Array.lastIndexOf (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf )
144
211
145
212
### map :: ` (a -> b) -> [a] -> [b] `
146
213
Applies a function over each element in the given array, returning a new array with each functions results.
147
214
215
+ ``` js
216
+ map (x => x * 2 )([1 , 2 , 3 ]) // => 2, 4, 6
217
+ ```
148
218
> See [ Array.map (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map )
149
219
150
220
### pipe :: ` ((a -> b), (b -> c), ..., (e -> f)) -> a -> f `
151
221
Takes an initial value that is passed to the first function in the parameter list.
152
222
The return value of each subsequent function is passed to the following function.
153
223
The return value of the last function is returned from pipe.
154
224
225
+ ``` js
226
+ const arr = [1 , 2 , 3 , 4 , 5 ]
227
+ pipe (
228
+ unshift (0 ),
229
+ concat ([6 , 7 , 8 ])
230
+ )(arr) // => [0, 1, 2, 3, 4, 5, 6, 7, 8]
231
+ ```
155
232
> See [ Array.pipe (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pipe )
156
233
157
234
### pop :: ` [a] -> [a] `
158
235
Returns a new array without the last item
159
236
237
+ ``` js
238
+ pop ([1 , 2 , 3 , 4 , 5 ]) // => [1, 2, 3, 4]
239
+ ```
160
240
> See [ Array.pop (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop )
161
241
162
242
### push :: ` a -> [a] -> [a] `
163
243
Returns a new array with the new element appended to the end of the original array.
164
244
245
+ ``` js
246
+ push (5 )([1 , 2 , 3 , 4 ]) // => [1, 2, 3, 4, 5]
247
+ ```
165
248
> See [ Array.push (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push )
166
249
167
250
### reduce :: ` ((a, b) -> a) -> a -> [b] -> a `
0 commit comments