-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
278 lines (274 loc) · 7.18 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
const factory = require('./factory')
const isIterable = require('./internal/isIterable')
const chunk = require('./chunk')
const combinations = require('./combinations')
const concat = require('./concat')
const cycle = require('./cycle')
const drop = require('./drop')
const dropWhile = require('./dropWhile')
const entries = require('./entries')
const every = require('./every')
const filter = require('./filter')
const find = require('./find')
const findEntry = require('./findEntry')
const findIndex = require('./findIndex')
const flatten = require('./flatten')
const groupBy = require('./groupBy')
const has = require('./has')
const includes = require('./includes')
const indexOf = require('./indexOf')
const indexOfFrom = require('./indexOfFrom')
const isEmpty = require('is-empty-iterable')
const isEqual = require('./isEqual')
const isEqualBy = require('./isEqualBy')
const isEqualWith = require('./isEqualWith')
const map = require('./map')
const nth = require('./nth')
const padEnd = require('./padEnd')
const permutations = require('./permutations')
const power = require('./power')
const powerSet = require('./powerSet')
const product = require('./product')
const range = require('./range')
const rangeByStep = require('./rangeByStep')
const reduce = require('./reduce')
const reduceRight = require('./reduceRight')
const repeat = require('./repeat')
const slice = require('./slice')
const some = require('./some')
const take = require('./take')
const takeWhile = require('./takeWhile')
const tap = require('./tap')
const toString = require('./toString')
const transpose = require('./transpose')
const transposeLongest = require('./transposeLongest')
const uniq = require('./uniq')
const uniqBy = require('./uniqBy')
const uniqWith = require('./uniqWith')
const variations = require('./variations')
const zip = require('./zip')
const zipLongest = require('./zipLongest')
const Num = {
predicate: n => ({}).toString.call(n).slice(8, -1) === 'Number',
type: 'a number'
}
const Fn = {
predicate: f => typeof f === 'function',
type: 'a function'
}
const Iterable = {
predicate: isIterable,
type: 'an iterable'
}
const Any = {
predicate: () => true
}
const functionValidation = [Fn, Iterable]
const reduceValidation = [Fn, Any, Iterable]
const numberValidation = [Num, Iterable]
const iterableValidation = [Iterable]
const anyValueValidation = [Any, Iterable]
const twoIterableValidation = [Iterable, Iterable]
const twoNumberValidation = [Num, Num, Iterable]
const Iterum = factory({
staticMethods: {
range: {
fn: range,
validation: [Num, Num]
},
rangeByStep: {
fn: rangeByStep,
validation: [Num, Num, Num]
}
},
methods: {
chunk: {
fn: chunk,
validation: numberValidation
},
combinations: {
fn: combinations,
validation: numberValidation
},
concat: {
fn: concat,
validation: twoIterableValidation,
binary: true
},
cycle: {
fn: cycle,
validation: iterableValidation
},
drop: {
fn: drop,
validation: numberValidation
},
dropWhile: {
fn: dropWhile,
validation: functionValidation
},
entries: {
fn: entries,
validation: iterableValidation
},
every: {
fn: every,
validation: functionValidation
},
filter: {
fn: filter,
validation: functionValidation
},
find: {
fn: find,
validation: functionValidation
},
findEntry: {
fn: findEntry,
validation: functionValidation
},
findIndex: {
fn: findIndex,
validation: functionValidation
},
flatten: {
fn: flatten,
validation: numberValidation
},
has: {
fn: has,
validation: numberValidation
},
includes: {
fn: includes,
validation: anyValueValidation
},
indexOf: {
fn: indexOf,
validation: anyValueValidation
},
indexOfFrom: {
fn: indexOfFrom,
validation: [Any, Num, Iterable]
},
isEmpty: {
fn: isEmpty,
validation: iterableValidation
},
isEqual: {
fn: isEqual,
validation: [Any, Any]
},
isEqualBy: {
fn: isEqualBy,
validation: [Fn, Any, Any]
},
isEqualWith: {
fn: isEqualWith,
validation: [Fn, Any, Any]
},
map: {
fn: map,
validation: functionValidation
},
nth: {
fn: nth,
validation: numberValidation
},
groupBy: {
fn: groupBy,
validation: functionValidation
},
padEnd: {
fn: padEnd,
validation: [Num, Any, Iterable]
},
permutations: {
fn: permutations,
validation: iterableValidation
},
power: {
fn: power,
validation: numberValidation
},
powerSet: {
fn: powerSet,
validation: iterableValidation
},
product: {
fn: product,
validation: iterableValidation
},
reduce: {
fn: reduce,
validation: reduceValidation
},
reduceRight: {
fn: reduceRight,
validation: reduceValidation
},
repeat: {
fn: repeat,
validation: numberValidation
},
slice: {
fn: slice,
validation: twoNumberValidation
},
some: {
fn: some,
validation: functionValidation
},
take: {
fn: take,
validation: numberValidation
},
takeWhile: {
fn: takeWhile,
validation: functionValidation
},
tap: {
fn: tap,
validation: functionValidation
},
toString: {
fn: toString,
validation: iterableValidation
},
transpose: {
fn: transpose,
validation: iterableValidation
},
transposeLongest: {
fn: transposeLongest,
validation: iterableValidation
},
uniq: {
fn: uniq,
validation: iterableValidation
},
uniqBy: {
fn: uniqBy,
validation: functionValidation
},
uniqWith: {
fn: uniqWith,
validation: functionValidation
},
variations: {
fn: variations,
validation: numberValidation
},
zip: {
fn: zip,
validation: twoIterableValidation,
binary: true
},
zipLongest: {
fn: zipLongest,
validation: twoIterableValidation,
binary: true
}
}
})
module.exports = Iterum