-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
_stepCat.js
46 lines (43 loc) · 1.08 KB
/
_stepCat.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
import _objectAssign from './_objectAssign';
import _identity from './_identity';
import _isArrayLike from './_isArrayLike';
import _isTransformer from './_isTransformer';
import objOf from '../objOf';
var _stepCatArray = {
'@@transducer/init': Array,
'@@transducer/step': function(xs, x) {
xs.push(x);
return xs;
},
'@@transducer/result': _identity
};
var _stepCatString = {
'@@transducer/init': String,
'@@transducer/step': function(a, b) { return a + b; },
'@@transducer/result': _identity
};
var _stepCatObject = {
'@@transducer/init': Object,
'@@transducer/step': function(result, input) {
return _objectAssign(
result,
_isArrayLike(input) ? objOf(input[0], input[1]) : input
);
},
'@@transducer/result': _identity
};
export default function _stepCat(obj) {
if (_isTransformer(obj)) {
return obj;
}
if (_isArrayLike(obj)) {
return _stepCatArray;
}
if (typeof obj === 'string') {
return _stepCatString;
}
if (typeof obj === 'object') {
return _stepCatObject;
}
throw new Error('Cannot create transformer for ' + obj);
}