2
2
// Array creation --------------------------------------------------------------
3
3
//------------------------------------------------------------------------------
4
4
5
- export const range = function ( start ) {
6
- return function ( end ) {
7
- var step = start > end ? - 1 : 1 ;
8
- var result = new Array ( step * ( end - start ) + 1 ) ;
9
- var i = start , n = 0 ;
10
- while ( i !== end ) {
11
- result [ n ++ ] = i ;
12
- i += step ;
13
- }
14
- result [ n ] = i ;
15
- return result ;
16
- } ;
5
+ export const rangeImpl = function ( start , end ) {
6
+ var step = start > end ? - 1 : 1 ;
7
+ var result = new Array ( step * ( end - start ) + 1 ) ;
8
+ var i = start , n = 0 ;
9
+ while ( i !== end ) {
10
+ result [ n ++ ] = i ;
11
+ i += step ;
12
+ }
13
+ result [ n ] = i ;
14
+ return result ;
17
15
} ;
18
16
19
- var replicateFill = function ( count ) {
20
- return function ( value ) {
21
- if ( count < 1 ) {
22
- return [ ] ;
23
- }
24
- var result = new Array ( count ) ;
25
- return result . fill ( value ) ;
26
- } ;
17
+ var replicateFill = function ( count , value ) {
18
+ if ( count < 1 ) {
19
+ return [ ] ;
20
+ }
21
+ var result = new Array ( count ) ;
22
+ return result . fill ( value ) ;
27
23
} ;
28
24
29
- var replicatePolyfill = function ( count ) {
30
- return function ( value ) {
31
- var result = [ ] ;
32
- var n = 0 ;
33
- for ( var i = 0 ; i < count ; i ++ ) {
34
- result [ n ++ ] = value ;
35
- }
36
- return result ;
37
- } ;
25
+ var replicatePolyfill = function ( count , value ) {
26
+ var result = [ ] ;
27
+ var n = 0 ;
28
+ for ( var i = 0 ; i < count ; i ++ ) {
29
+ result [ n ++ ] = value ;
30
+ }
31
+ return result ;
38
32
} ;
39
33
40
34
// In browsers that have Array.prototype.fill we use it, as it's faster.
41
- export const replicate = typeof Array . prototype . fill === "function" ? replicateFill : replicatePolyfill ;
35
+ export const replicateImpl = typeof Array . prototype . fill === "function" ? replicateFill : replicatePolyfill ;
42
36
43
37
export const fromFoldableImpl = ( function ( ) {
44
38
function Cons ( head , tail ) {
@@ -64,10 +58,8 @@ export const fromFoldableImpl = (function () {
64
58
return result ;
65
59
}
66
60
67
- return function ( foldr ) {
68
- return function ( xs ) {
69
- return listToArray ( foldr ( curryCons ) ( emptyList ) ( xs ) ) ;
70
- } ;
61
+ return function ( foldr , xs ) {
62
+ return listToArray ( foldr ( curryCons ) ( emptyList ) ( xs ) ) ;
71
63
} ;
72
64
} ) ( ) ;
73
65
@@ -83,109 +75,59 @@ export const length = function (xs) {
83
75
// Non-indexed reads -----------------------------------------------------------
84
76
//------------------------------------------------------------------------------
85
77
86
- export const unconsImpl = function ( empty ) {
87
- return function ( next ) {
88
- return function ( xs ) {
89
- return xs . length === 0 ? empty ( { } ) : next ( xs [ 0 ] ) ( xs . slice ( 1 ) ) ;
90
- } ;
91
- } ;
78
+ export const unconsImpl = function ( empty , next , xs ) {
79
+ return xs . length === 0 ? empty ( { } ) : next ( xs [ 0 ] ) ( xs . slice ( 1 ) ) ;
92
80
} ;
93
81
94
82
//------------------------------------------------------------------------------
95
83
// Indexed operations ----------------------------------------------------------
96
84
//------------------------------------------------------------------------------
97
85
98
- export const indexImpl = function ( just ) {
99
- return function ( nothing ) {
100
- return function ( xs ) {
101
- return function ( i ) {
102
- return i < 0 || i >= xs . length ? nothing : just ( xs [ i ] ) ;
103
- } ;
104
- } ;
105
- } ;
86
+ export const indexImpl = function ( just , nothing , xs , i ) {
87
+ return i < 0 || i >= xs . length ? nothing : just ( xs [ i ] ) ;
106
88
} ;
107
89
108
- export const findMapImpl = function ( nothing ) {
109
- return function ( isJust ) {
110
- return function ( f ) {
111
- return function ( xs ) {
112
- for ( var i = 0 ; i < xs . length ; i ++ ) {
113
- var result = f ( xs [ i ] ) ;
114
- if ( isJust ( result ) ) return result ;
115
- }
116
- return nothing ;
117
- } ;
118
- } ;
119
- } ;
90
+ export const findMapImpl = function ( nothing , isJust , f , xs ) {
91
+ for ( var i = 0 ; i < xs . length ; i ++ ) {
92
+ var result = f ( xs [ i ] ) ;
93
+ if ( isJust ( result ) ) return result ;
94
+ }
95
+ return nothing ;
120
96
} ;
121
97
122
- export const findIndexImpl = function ( just ) {
123
- return function ( nothing ) {
124
- return function ( f ) {
125
- return function ( xs ) {
126
- for ( var i = 0 , l = xs . length ; i < l ; i ++ ) {
127
- if ( f ( xs [ i ] ) ) return just ( i ) ;
128
- }
129
- return nothing ;
130
- } ;
131
- } ;
132
- } ;
98
+ export const findIndexImpl = function ( just , nothing , f , xs ) {
99
+ for ( var i = 0 , l = xs . length ; i < l ; i ++ ) {
100
+ if ( f ( xs [ i ] ) ) return just ( i ) ;
101
+ }
102
+ return nothing ;
133
103
} ;
134
104
135
- export const findLastIndexImpl = function ( just ) {
136
- return function ( nothing ) {
137
- return function ( f ) {
138
- return function ( xs ) {
139
- for ( var i = xs . length - 1 ; i >= 0 ; i -- ) {
140
- if ( f ( xs [ i ] ) ) return just ( i ) ;
141
- }
142
- return nothing ;
143
- } ;
144
- } ;
145
- } ;
105
+ export const findLastIndexImpl = function ( just , nothing , f , xs ) {
106
+ for ( var i = xs . length - 1 ; i >= 0 ; i -- ) {
107
+ if ( f ( xs [ i ] ) ) return just ( i ) ;
108
+ }
109
+ return nothing ;
146
110
} ;
147
111
148
- export const _insertAt = function ( just ) {
149
- return function ( nothing ) {
150
- return function ( i ) {
151
- return function ( a ) {
152
- return function ( l ) {
153
- if ( i < 0 || i > l . length ) return nothing ;
154
- var l1 = l . slice ( ) ;
155
- l1 . splice ( i , 0 , a ) ;
156
- return just ( l1 ) ;
157
- } ;
158
- } ;
159
- } ;
160
- } ;
112
+ export const _insertAt = function ( just , nothing , i , a , l ) {
113
+ if ( i < 0 || i > l . length ) return nothing ;
114
+ var l1 = l . slice ( ) ;
115
+ l1 . splice ( i , 0 , a ) ;
116
+ return just ( l1 ) ;
161
117
} ;
162
118
163
- export const _deleteAt = function ( just ) {
164
- return function ( nothing ) {
165
- return function ( i ) {
166
- return function ( l ) {
167
- if ( i < 0 || i >= l . length ) return nothing ;
168
- var l1 = l . slice ( ) ;
169
- l1 . splice ( i , 1 ) ;
170
- return just ( l1 ) ;
171
- } ;
172
- } ;
173
- } ;
119
+ export const _deleteAt = function ( just , nothing , i , l ) {
120
+ if ( i < 0 || i >= l . length ) return nothing ;
121
+ var l1 = l . slice ( ) ;
122
+ l1 . splice ( i , 1 ) ;
123
+ return just ( l1 ) ;
174
124
} ;
175
125
176
- export const _updateAt = function ( just ) {
177
- return function ( nothing ) {
178
- return function ( i ) {
179
- return function ( a ) {
180
- return function ( l ) {
181
- if ( i < 0 || i >= l . length ) return nothing ;
182
- var l1 = l . slice ( ) ;
183
- l1 [ i ] = a ;
184
- return just ( l1 ) ;
185
- } ;
186
- } ;
187
- } ;
188
- } ;
126
+ export const _updateAt = function ( just , nothing , i , a , l ) {
127
+ if ( i < 0 || i >= l . length ) return nothing ;
128
+ var l1 = l . slice ( ) ;
129
+ l1 [ i ] = a ;
130
+ return just ( l1 ) ;
189
131
} ;
190
132
191
133
//------------------------------------------------------------------------------
@@ -213,55 +155,43 @@ export const concat = function (xss) {
213
155
return result ;
214
156
} ;
215
157
216
- export const filter = function ( f ) {
217
- return function ( xs ) {
218
- return xs . filter ( f ) ;
219
- } ;
158
+ export const filterImpl = function ( f , xs ) {
159
+ return xs . filter ( f ) ;
220
160
} ;
221
161
222
- export const partition = function ( f ) {
223
- return function ( xs ) {
224
- var yes = [ ] ;
225
- var no = [ ] ;
226
- for ( var i = 0 ; i < xs . length ; i ++ ) {
227
- var x = xs [ i ] ;
228
- if ( f ( x ) )
229
- yes . push ( x ) ;
230
- else
231
- no . push ( x ) ;
232
- }
233
- return { yes : yes , no : no } ;
234
- } ;
162
+ export const partitionImpl = function ( f , xs ) {
163
+ var yes = [ ] ;
164
+ var no = [ ] ;
165
+ for ( var i = 0 ; i < xs . length ; i ++ ) {
166
+ var x = xs [ i ] ;
167
+ if ( f ( x ) )
168
+ yes . push ( x ) ;
169
+ else
170
+ no . push ( x ) ;
171
+ }
172
+ return { yes : yes , no : no } ;
235
173
} ;
236
174
237
- export const scanl = function ( f ) {
238
- return function ( b ) {
239
- return function ( xs ) {
240
- var len = xs . length ;
241
- var acc = b ;
242
- var out = new Array ( len ) ;
243
- for ( var i = 0 ; i < len ; i ++ ) {
244
- acc = f ( acc ) ( xs [ i ] ) ;
245
- out [ i ] = acc ;
246
- }
247
- return out ;
248
- } ;
249
- } ;
175
+ export const scanlImpl = function ( f , b , xs ) {
176
+ var len = xs . length ;
177
+ var acc = b ;
178
+ var out = new Array ( len ) ;
179
+ for ( var i = 0 ; i < len ; i ++ ) {
180
+ acc = f ( acc ) ( xs [ i ] ) ;
181
+ out [ i ] = acc ;
182
+ }
183
+ return out ;
250
184
} ;
251
185
252
- export const scanr = function ( f ) {
253
- return function ( b ) {
254
- return function ( xs ) {
255
- var len = xs . length ;
256
- var acc = b ;
257
- var out = new Array ( len ) ;
258
- for ( var i = len - 1 ; i >= 0 ; i -- ) {
259
- acc = f ( xs [ i ] ) ( acc ) ;
260
- out [ i ] = acc ;
261
- }
262
- return out ;
263
- } ;
264
- } ;
186
+ export const scanrImpl = function ( f , b , xs ) {
187
+ var len = xs . length ;
188
+ var acc = b ;
189
+ var out = new Array ( len ) ;
190
+ for ( var i = len - 1 ; i >= 0 ; i -- ) {
191
+ acc = f ( xs [ i ] ) ( acc ) ;
192
+ out [ i ] = acc ;
193
+ }
194
+ return out ;
265
195
} ;
266
196
267
197
//------------------------------------------------------------------------------
@@ -306,81 +236,63 @@ export const sortByImpl = (function () {
306
236
}
307
237
}
308
238
309
- return function ( compare ) {
310
- return function ( fromOrdering ) {
311
- return function ( xs ) {
312
- var out ;
239
+ return function ( compare , fromOrdering , xs ) {
240
+ var out ;
313
241
314
- if ( xs . length < 2 ) return xs ;
242
+ if ( xs . length < 2 ) return xs ;
315
243
316
- out = xs . slice ( 0 ) ;
317
- mergeFromTo ( compare , fromOrdering , out , xs . slice ( 0 ) , 0 , xs . length ) ;
244
+ out = xs . slice ( 0 ) ;
245
+ mergeFromTo ( compare , fromOrdering , out , xs . slice ( 0 ) , 0 , xs . length ) ;
318
246
319
- return out ;
320
- } ;
321
- } ;
247
+ return out ;
322
248
} ;
323
249
} ) ( ) ;
324
250
325
251
//------------------------------------------------------------------------------
326
252
// Subarrays -------------------------------------------------------------------
327
253
//------------------------------------------------------------------------------
328
254
329
- export const slice = function ( s ) {
330
- return function ( e ) {
331
- return function ( l ) {
332
- return l . slice ( s , e ) ;
333
- } ;
334
- } ;
255
+ export const sliceImpl = function ( s , e , l ) {
256
+ return l . slice ( s , e ) ;
335
257
} ;
336
258
337
259
//------------------------------------------------------------------------------
338
260
// Zipping ---------------------------------------------------------------------
339
261
//------------------------------------------------------------------------------
340
262
341
- export const zipWith = function ( f ) {
342
- return function ( xs ) {
343
- return function ( ys ) {
344
- var l = xs . length < ys . length ? xs . length : ys . length ;
345
- var result = new Array ( l ) ;
346
- for ( var i = 0 ; i < l ; i ++ ) {
347
- result [ i ] = f ( xs [ i ] ) ( ys [ i ] ) ;
348
- }
349
- return result ;
350
- } ;
351
- } ;
263
+ export const zipWithImpl = function ( f , xs , ys ) {
264
+ var l = xs . length < ys . length ? xs . length : ys . length ;
265
+ var result = new Array ( l ) ;
266
+ for ( var i = 0 ; i < l ; i ++ ) {
267
+ result [ i ] = f ( xs [ i ] ) ( ys [ i ] ) ;
268
+ }
269
+ return result ;
352
270
} ;
353
271
354
272
//------------------------------------------------------------------------------
355
273
// Folding ---------------------------------------------------------------------
356
274
//------------------------------------------------------------------------------
357
275
358
- export const any = function ( p ) {
359
- return function ( xs ) {
360
- var len = xs . length ;
361
- for ( var i = 0 ; i < len ; i ++ ) {
362
- if ( p ( xs [ i ] ) ) return true ;
363
- }
364
- return false ;
365
- } ;
276
+ export const anyImpl = function ( p , xs ) {
277
+ var len = xs . length ;
278
+ for ( var i = 0 ; i < len ; i ++ ) {
279
+ if ( p ( xs [ i ] ) ) return true ;
280
+ }
281
+ return false ;
366
282
} ;
367
283
368
- export const all = function ( p ) {
369
- return function ( xs ) {
370
- var len = xs . length ;
371
- for ( var i = 0 ; i < len ; i ++ ) {
372
- if ( ! p ( xs [ i ] ) ) return false ;
373
- }
374
- return true ;
375
- } ;
284
+ export const allImpl = function ( p , xs ) {
285
+ var len = xs . length ;
286
+ for ( var i = 0 ; i < len ; i ++ ) {
287
+ if ( ! p ( xs [ i ] ) ) return false ;
288
+ }
289
+ return true ;
376
290
} ;
377
291
378
292
//------------------------------------------------------------------------------
379
293
// Partial ---------------------------------------------------------------------
380
294
//------------------------------------------------------------------------------
381
295
382
- export const unsafeIndexImpl = function ( xs ) {
383
- return function ( n ) {
384
- return xs [ n ] ;
385
- } ;
296
+ export const unsafeIndexImpl = function ( xs , n ) {
297
+ return xs [ n ] ;
386
298
} ;
0 commit comments