Comparing version 1.0.0-alpha-08 to 1.0.0-alpha-09
@@ -21,3 +21,3 @@ // Generated by CoffeeScript 1.9.1 | ||
describe("Iterator functions", function(context) { | ||
var _foldr, _unzip, add, all, any, assoc, binary, collect, detach, first, flatten, flip, fold, foldr, is_function, is_iterable, is_iterator, iterate, iterator, last, leave, map, maybe_iterator_f, negate, odd, partition, project, property, ref2, reject, sample, second, select, skip, take, ternary, third, unzip, w, zip; | ||
var _foldr, _unzip, add, all, any, assoc, binary, collect, detach, each, first, flatten, flip, fold, foldr, is_function, is_iterable, is_iterator, iterate, iterator, last, leave, map, negate, odd, partition, project, property, ref2, reject, sample, second, select, skip, take, ternary, third, unzip, w, wrap, zip; | ||
is_iterable = function(x) { | ||
@@ -29,2 +29,7 @@ return x[Symbol.iterator] != null; | ||
}); | ||
is_iterator = function(x) { | ||
return (x != null ? x.next : void 0) != null; | ||
}; | ||
is_function = require("./type").is_function; | ||
wrap = require("./core").wrap; | ||
iterator = function(x) { | ||
@@ -35,36 +40,31 @@ if (is_iterable(x)) { | ||
return x; | ||
} else if ((is_function(x)) && (x.length === 0)) { | ||
return { | ||
next: x | ||
}; | ||
} else { | ||
throw new TypeError("Value is not an iterable or an iterator"); | ||
return { | ||
next: wrap(x) | ||
}; | ||
} | ||
}; | ||
context.test("is_iterator", function() { | ||
return assert(is_iterator(iterator([1, 2, 3]))); | ||
}); | ||
context.test("iterator", function() { | ||
var is_function; | ||
is_function = require("../src/index").is_function; | ||
return assert(is_function((iterator([1, 2, 3])).next)); | ||
}); | ||
is_iterator = function(x) { | ||
return x.next != null; | ||
}; | ||
context.test("is_iterator", function() { | ||
return assert(is_iterator(iterator([1, 2, 3]))); | ||
}); | ||
is_function = require("./type").is_function; | ||
maybe_iterator_f = function(x) { | ||
return (is_function(x)) && (x.length === 0) && !((is_iterable(x)) || (is_iterator(x))); | ||
}; | ||
iterate = function(x) { | ||
if (!maybe_iterator_f(x)) { | ||
return (function(it) { | ||
return async(function*() { | ||
var done, ref2, value; | ||
ref2 = it.next(), done = ref2.done, value = ref2.value; | ||
return { | ||
done: done, | ||
value: (yield promise(value)) | ||
}; | ||
}); | ||
})(iterator(x)); | ||
} else { | ||
return x; | ||
} | ||
var f, i; | ||
i = iterator(x); | ||
f = async(function*() { | ||
var done, ref2, value; | ||
ref2 = i.next(), done = ref2.done, value = ref2.value; | ||
return { | ||
done: done, | ||
value: (yield promise(value)) | ||
}; | ||
}); | ||
f[Symbol.iterator] = wrap(i); | ||
return f; | ||
}; | ||
@@ -74,4 +74,3 @@ context.test("iterate", function*() { | ||
i = iterate([1, 2, 3]); | ||
assert(maybe_iterator_f(i)); | ||
assert(maybe_iterator_f(iterate(i))); | ||
assert(is_iterable(i)); | ||
assert(((yield i())).value === 1); | ||
@@ -82,3 +81,2 @@ assert(((yield i())).value === 2); | ||
}); | ||
leave = require("./array").leave; | ||
collect = async(function*(i) { | ||
@@ -90,3 +88,3 @@ var done, ref2, result, value; | ||
while (!done) { | ||
ref2 = (yield promise(i())), done = ref2.done, value = ref2.value; | ||
ref2 = (yield i()), done = ref2.done, value = ref2.value; | ||
if (!done) { | ||
@@ -99,40 +97,35 @@ result.push(value); | ||
context.test("collect", function*() { | ||
var first, i; | ||
i = (function() { | ||
var n; | ||
n = 5; | ||
return function() { | ||
if (n-- > 0) { | ||
return { | ||
value: n, | ||
done: false | ||
}; | ||
} else { | ||
return { | ||
done: true | ||
}; | ||
} | ||
}; | ||
})(); | ||
var first; | ||
first = require("./array").first; | ||
return assert((first((yield collect(i)))) === 4); | ||
return assert((first((yield collect([1, 2, 3, 4, 5])))) === 1); | ||
}); | ||
map = curry(function(f, x) { | ||
return (function(i) { | ||
return async(function*() { | ||
var done, ref2, value; | ||
ref2 = (yield i()), done = ref2.done, value = ref2.value; | ||
if (!done) { | ||
return { | ||
done: done, | ||
value: (yield promise(f(value))) | ||
}; | ||
} else { | ||
return { | ||
done: done | ||
}; | ||
} | ||
}); | ||
})(iterate(x)); | ||
each = async(function*(f, i) { | ||
var done, ref2, value; | ||
i = iterate(i); | ||
done = false; | ||
while (!done) { | ||
ref2 = (yield i()), done = ref2.done, value = ref2.value; | ||
if (!done) { | ||
f(value); | ||
} | ||
} | ||
return void 0; | ||
}); | ||
map = curry(function(f, i) { | ||
i = iterate(i); | ||
return async(function*() { | ||
var done, ref2, value; | ||
ref2 = (yield i()), done = ref2.done, value = ref2.value; | ||
if (!done) { | ||
return { | ||
done: done, | ||
value: (yield promise(f(value))) | ||
}; | ||
} else { | ||
return { | ||
done: done | ||
}; | ||
} | ||
}); | ||
}); | ||
context.test("map", function() { | ||
@@ -139,0 +132,0 @@ var double, x; |
@@ -12,3 +12,3 @@ // Generated by CoffeeScript 1.9.1 | ||
describe("Numeric functions", function(context) { | ||
var add, div, even, gt, gte, lt, lte, max, min, mod, mul, odd, sub; | ||
var abs, add, div, even, gt, gte, lt, lte, max, min, mod, mul, odd, pow, sub; | ||
gte = curry(function(x, y) { | ||
@@ -47,3 +47,3 @@ return y >= x; | ||
}); | ||
min = Math.min, max = Math.max; | ||
min = Math.min, max = Math.max, abs = Math.abs, pow = Math.pow; | ||
return module.exports = { | ||
@@ -62,3 +62,4 @@ gt: gt, | ||
min: min, | ||
max: max | ||
max: max, | ||
abs: abs | ||
}; | ||
@@ -65,0 +66,0 @@ }); |
{ | ||
"name": "fairmont", | ||
"version": "1.0.0-alpha-08", | ||
"version": "1.0.0-alpha-09", | ||
"description": "A collection of useful functions and utilities.", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -27,3 +27,3 @@ # Fairmont | ||
We've seamlessly integrated asychronous functions with synchronous functions, even when doing composition. Behind the scenes we're using iterators to avoid multiple passes across the data. We make two passes here, even though it appears that we're making five. | ||
We've seamlessly integrated asynchronous functions with synchronous functions, even when doing composition. Behind the scenes we're using iterators to avoid multiple passes across the data. We make two passes here, even though it appears that we're making five. | ||
@@ -30,0 +30,0 @@ Fairmont is also a literate programming project—the documentation, code, examples, and tests are together, making it easy to see what a function does, how it does it, and why it does it that particular way. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
85704
1585