@@ -68,100 +68,183 @@ compose(
6868
6969## Api
7070### compose :: ` ((e -> f), ..., (b -> c), (a -> b)) -> a -> f `
71+
7172Evaluates the provided functions, right to left, passing the return value
7273of each function to the next in line.
7374The initial function is passed the initial value provided to comopse.
7475The 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+ ```
7584### concat :: ` [a] -> ([a], ..., [a]) -> [a] `
7685Concatenates two arrays
86+
7787``` 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]
7989concat ([4 , 5 ])([1 ,2 ], [3 ]) // => [1, 2, 3, 4, 5]
8090```
8191> See [ Array.concat (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat )
8292
8393### copyWithin :: ` (Int, Int, Int) -> [a] -> [a] `
8494Makes a shallow copy of part of an array and overwrites another location in the same with the copy. Size is kept constant.
8595
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+ ```
86101> See [ Array.copyWithin (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin )
87102
88103### entries:: ` [a] -> [b] `
89104Return an iterator over key, value pairs from the array.
90105
106+ ``` js
107+ const iterator = entries ([1 , 2 , 3 , 4 , 5 ])
108+ iterator .next ()) // => { value: [0, 1], done: false }
109+ ```
91110> See [ Array.entries (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries )
92111
93112### every :: ` ((a, Int, [a]) -> Boolean) -> [a] -> Boolean `
94113Applies 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.
95114
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+ ```
96120> See [ Array.every (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every )
97121
98122### fill :: ` (a, Int, Int) -> [a] -> [a] `
99123Fills a portion of the given array putting the same new value into each slot.
100124
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+ ```
101130> See [ Array.fill (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill )
102131
103132### filter :: ` ((a, Int, [a]) -> Boolean) -> [a] -> [a] `
104133Returns a new array containing only those elements of the given array that pass the given predicate.
105134
135+ ``` js
136+ const predicate = x => x < 3
137+ filter (predicate)([1 , 2 , 3 , 4 , 5 ]) // => [1, 2]
138+ ```
106139> See [ Array.filter (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter )
107140
108141### find :: ` (a -> Boolean) -> [a] -> a | undefined `
109142Finds and returns the first element in the given array that matches the given predicate. If no element passes, undefined is returned.
110143
144+ ``` js
145+ const predicate = x => x === 3
146+ find (predicate)([1 , 2 , 3 ]) // => 3
147+ find (predicate)([1 , 2 ]) // => undefined
148+ ```
111149> See [ Array.find (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find )
112150
113151### findIndex :: ` (a -> Boolean) -> [a] -> Int `
114152Returns the index of the first element in the given array that matches the given predicate. If no element passes, -1 is returned.
115153
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+ ```
116160> See [ Array.findIndex (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex )
117161
118162### includes :: ` a -> [a] -> Boolean `
119163Returns true if the given element is in the given array, otherwise false.
120164
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+ ```
121173> See [ Array.includes (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes )
122174
123175### indexOf :: ` (a, Int) -> [a] -> Int `
124176Returns the index of the given element if it is in the given array, otherwise -1.
125177The 2nd parameter can be used to change where it starts looking.
126178
179+ ``` js
180+ indexOf (3 )([1 , 2 , 3 , 4 , 5 ]) // => 2
181+ indexOf (3 , 3 )([[1 , 2 , 3 , 4 , 5 , 3 ]) // => 3
182+ ```
127183> See [ Array.indexOf (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf )
128184
129185### join :: ` String -> [a] -> String `
130186Converts each element of the array to a string and concatenates them together with the given string as a delimiter.
131187
188+ ``` js
189+ join (' -' )([1 , 2 , 3 ]) // => '1-2-3'
190+ ```
132191> See [ Array.join (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join )
133192
134193### keys :: ` [a] -> [Int] `
135194Return an iterator over keys from the array.
136195
196+ ``` js
197+ const iterator = keys ([1 , 2 , 3 , 4 , 5 ])
198+ iterator .next () // => { value: 0, done: false }
199+ ```
137200> See [ Array.keys (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys )
138201
139202### lastIndexOf :: ` (a, Int) -> [a] -> Int `
140203Works like indexOf but starts at the end and works backwards.
141204The 2nd parameter can be used to tell it where to start working backwards from.
142205
206+ ``` js
207+ lastIndexOf (1 )([1 , 2 , 3 , 1 ]) // => 3
208+ lastIndexOf (1 , - 2 )([1 , 2 , 3 , 1 ]) // => 0
209+ ```
143210> See [ Array.lastIndexOf (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf )
144211
145212### map :: ` (a -> b) -> [a] -> [b] `
146213Applies a function over each element in the given array, returning a new array with each functions results.
147214
215+ ``` js
216+ map (x => x * 2 )([1 , 2 , 3 ]) // => 2, 4, 6
217+ ```
148218> See [ Array.map (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map )
149219
150220### pipe :: ` ((a -> b), (b -> c), ..., (e -> f)) -> a -> f `
151221Takes an initial value that is passed to the first function in the parameter list.
152222The return value of each subsequent function is passed to the following function.
153223The return value of the last function is returned from pipe.
154224
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+ ```
155232> See [ Array.pipe (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pipe )
156233
157234### pop :: ` [a] -> [a] `
158235Returns a new array without the last item
159236
237+ ``` js
238+ pop ([1 , 2 , 3 , 4 , 5 ]) // => [1, 2, 3, 4]
239+ ```
160240> See [ Array.pop (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop )
161241
162242### push :: ` a -> [a] -> [a] `
163243Returns a new array with the new element appended to the end of the original array.
164244
245+ ``` js
246+ push (5 )([1 , 2 , 3 , 4 ]) // => [1, 2, 3, 4, 5]
247+ ```
165248> See [ Array.push (MDN)] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push )
166249
167250### reduce :: ` ((a, b) -> a) -> a -> [b] -> a `
0 commit comments