Skip to content

Commit 51a29de

Browse files
committedJan 28, 2017
2 parents 9467989 + 2cab510 commit 51a29de

File tree

3 files changed

+115
-37
lines changed

3 files changed

+115
-37
lines changed
 

‎README.md

+84-1
Original file line numberDiff line numberDiff line change
@@ -68,100 +68,183 @@ compose(
6868

6969
## Api
7070
### compose :: `((e -> f), ..., (b -> c), (a -> b)) -> a -> f`
71+
7172
Evaluates the provided functions, right to left, passing the return value
7273
of each function to the next in line.
7374
The initial function is passed the initial value provided to comopse.
7475
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+
```
7584
### concat :: `[a] -> ([a], ..., [a]) -> [a]`
7685
Concatenates 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]
7989
concat([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]`
8494
Makes 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]`
89104
Return 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`
94113
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.
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]`
99123
Fills 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]`
104133
Returns 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`
109142
Finds 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`
114152
Returns 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`
119163
Returns 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`
124176
Returns the index of the given element if it is in the given array, otherwise -1.
125177
The 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`
130186
Converts 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]`
135194
Return 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`
140203
Works like indexOf but starts at the end and works backwards.
141204
The 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]`
146213
Applies 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`
151221
Takes an initial value that is passed to the first function in the parameter list.
152222
The return value of each subsequent function is passed to the following function.
153223
The 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]`
158235
Returns 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]`
163243
Returns 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`

‎test/test.js

+31-32
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,21 @@ describe('api: copyWithin', () => {
8989
})
9090
})
9191

92+
describe('api: entries', () => {
93+
it('should return an interator that contains key values pair of given array', () => {
94+
const arr = [1, 2, 3, 4, 5]
95+
const iterator = entries(arr)
96+
expect(iterator.next()).toEqual({ value: [0, 1], done: false })
97+
})
98+
it('should not alter the original array', () => {
99+
const arr = [1, 2, 3, 4, 5]
100+
const iterator = entries(arr)
101+
iterator.next()
102+
iterator.next()
103+
expect(arr).toEqual([1, 2, 3, 4, 5])
104+
})
105+
})
106+
92107
describe('api: every', () => {
93108
it('should return false if any items do not pass predicate', () => {
94109
const arr = [1, 2, 3, 4, 5]
@@ -130,21 +145,6 @@ describe('api: fill', () => {
130145
})
131146
})
132147

133-
describe('api: entries', () => {
134-
it('should return an interator that contains key values pair of given array', () => {
135-
const arr = [1, 2, 3, 4, 5]
136-
const iterator = entries(arr)
137-
expect(iterator.next()).toEqual({ value: [0, 1], done: false })
138-
})
139-
it('should not alter the original array', () => {
140-
const arr = [1, 2, 3, 4, 5]
141-
const iterator = entries(arr)
142-
iterator.next()
143-
iterator.next()
144-
expect(arr).toEqual([1, 2, 3, 4, 5])
145-
})
146-
})
147-
148148
describe('api: filter', () => {
149149
it('should return items that pass the predicate', () => {
150150
const arr = [1, 2, 3, 4, 5]
@@ -243,6 +243,21 @@ describe('api: indexOf', () => {
243243
})
244244
})
245245

246+
describe('api: join', () => {
247+
it('should return a string with each item separated with character passed in', () => {
248+
var arr = [1, 2, 3, 4, 5]
249+
const separateByDash = join('-')
250+
const result = separateByDash(arr)
251+
expect(result).toEqual('1-2-3-4-5')
252+
})
253+
it('should not alter the original array', () => {
254+
var arr = [1, 2, 3, 4, 5]
255+
const separateByDash = join('-')
256+
const result = separateByDash(arr)
257+
expect(arr).toEqual([1, 2, 3, 4, 5])
258+
})
259+
})
260+
246261
describe('api: keys', () => {
247262
it('should return an iterator of keys of given array', () => {
248263
const arr = [1, 2, 3, 4, 5]
@@ -258,20 +273,7 @@ describe('api: keys', () => {
258273
})
259274
})
260275

261-
describe('api: join', () => {
262-
it('should return a string with each item separated with character passed in', () => {
263-
var arr = [1, 2, 3, 4, 5]
264-
const separateByDash = join('-')
265-
const result = separateByDash(arr)
266-
expect(result).toEqual('1-2-3-4-5')
267-
})
268-
it('should not alter the original array', () => {
269-
var arr = [1, 2, 3, 4, 5]
270-
const separateByDash = join('-')
271-
const result = separateByDash(arr)
272-
expect(arr).toEqual([1, 2, 3, 4, 5])
273-
})
274-
})
276+
275277

276278
describe('api: lastIndexOf', () => {
277279
it('should find the index of the last occurrence of an element', () => {
@@ -362,7 +364,6 @@ describe('api: some', () => {
362364
})
363365
})
364366

365-
/*////////////// Maybe ///////////*/
366367
describe('api: reverse', () => {
367368
it('should return array reversed', () => {
368369
const arr = [1, 2, 3, 4, 5]
@@ -502,8 +503,6 @@ describe('api: sort', () => {
502503
})
503504
})
504505

505-
/*/////////////// end maybe //////////*/
506-
507506
describe('api: compose', () => {
508507
const is = a => b => {
509508
expect(a).toEqual(b)

‎testee.remote.json

-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
},
77
"root": "./",
88
"browsers": [{
9-
"os": "win",
10-
"browser": "ie",
11-
"version": 11.0
12-
}, {
139
"os": "ios",
1410
"device": "iPad Mini",
1511
"version": 6.0

0 commit comments

Comments
 (0)