-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcombinators.js
75 lines (75 loc) · 2.61 KB
/
combinators.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
// Generated by CoffeeScript 2.0.0-beta7
void function () {
var cache$, listOf, listOfExactly, oneOf, randomBool, randomElement;
cache$ = require('./random');
randomBool = cache$.randomBool;
randomElement = cache$.randomElement;
exports.oneOf = oneOf = function (possibleGenerators) {
return function (args) {
var cache$1;
args = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
cache$1 = randomElement(possibleGenerators);
return (cache$1).apply(cache$1, [].slice.call(args).concat());
};
};
exports.listOf = listOf = function (possibleGenerators) {
return function (args) {
args = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
return function (accum$) {
var cache$1;
while (Math.random() < .5) {
accum$.push((cache$1 = oneOf(possibleGenerators)).apply(cache$1, [].slice.call(args).concat()));
}
return accum$;
}.call(this, []);
};
};
exports.listOfExactly = listOfExactly = function (n, possibleGenerators) {
return function (args) {
args = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
return function (accum$) {
var cache$2;
for (var cache$1 = function () {
var accum$1;
accum$1 = [];
for (var i$ = 1; 1 <= n ? i$ <= n : i$ >= n; 1 <= n ? ++i$ : --i$)
accum$1.push(i$);
return accum$1;
}.apply(this, arguments), i$ = 0, length$ = cache$1.length; i$ < length$; ++i$) {
accum$.push((cache$2 = oneOf(possibleGenerators)).apply(cache$2, [].slice.call(args).concat()));
}
return accum$;
}.call(this, []);
};
};
exports.listOfAtLeast = function (min, possibleGenerators) {
return function (args) {
var cache$1, post, pre;
args = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
pre = listOfExactly(min, possibleGenerators)();
post = (cache$1 = listOf(possibleGenerators)).apply(cache$1, [].slice.call(args).concat());
return [].slice.call(pre).concat([].slice.call(post));
};
};
exports.maybe = function (generator) {
if (randomBool()) {
return generator;
} else {
return function () {
return null;
};
}
};
exports.construct = function (C) {
return function () {
return construct$(C, [].slice.call(arguments).concat());
};
};
function construct$(ctor, args) {
var fn = function () {
};
fn.prototype = ctor.prototype;
var child = new fn, result = ctor.apply(child, args);
return result === Object(result) ? result : child;
}
}.call(this);