diff --git a/index.js b/index.js index 35ac3aa..4bcf583 100644 --- a/index.js +++ b/index.js @@ -652,12 +652,12 @@ return this.reduce(function(acc, x) { return f(acc, x); }, initial); } - // Array$prototype$traverse :: Applicative f => Array a ~> (a -> f b, c -> f c) -> f (Array b) - function Array$prototype$traverse(f, of) { + // Array$prototype$traverse :: Applicative f => Array a ~> (TypeRep f, a -> f b) -> f (Array b) + function Array$prototype$traverse(typeRep, f) { var xs = this; function go(idx, n) { switch (n) { - case 0: return of([]); + case 0: return of(typeRep, []); case 2: return lift2(pair, f(xs[idx]), f(xs[idx + 1])); default: var m = Math.floor(n / 4) * 2; @@ -1395,7 +1395,7 @@ return Foldable.methods.reduce(foldable)(f, x); } - //# traverse :: (Applicative f, Traversable t) => (a -> f a, b -> f c, t b) -> f (t c) + //# traverse :: (Applicative f, Traversable t) => (TypeRep f, a -> f b, t a) -> f (t b) //. //. Function wrapper for [`fantasy-land/traverse`][]. //. @@ -1405,19 +1405,19 @@ //. See also [`sequence`](#sequence). //. //. ```javascript - //. > traverse(x => [x], x => x, [[1, 2, 3], [4, 5]]) + //. > traverse(Array, x => x, [[1, 2, 3], [4, 5]]) //. [[1, 4], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5]] //. //. > traverse(Identity, x => Identity(x + 1), [1, 2, 3]) //. Identity([2, 3, 4]) //. ``` - function traverse(of, f, traversable) { - return Traversable.methods.traverse(traversable)(f, of); + function traverse(typeRep, f, traversable) { + return Traversable.methods.traverse(traversable)(typeRep, f); } - //# sequence :: (Applicative f, Traversable t) => (a -> f a, t (f b)) -> f (t b) + //# sequence :: (Applicative f, Traversable t) => (TypeRep f, t (f a)) -> f (t a) //. - //. Inverts the given `t (f b)` to produce an `f (t b)`. + //. Inverts the given `t (f a)` to produce an `f (t a)`. //. //. This function is derived from [`traverse`](#traverse). //. @@ -1428,8 +1428,8 @@ //. > sequence(Identity, [Identity(1), Identity(2), Identity(3)]) //. Identity([1, 2, 3]) //. ``` - function sequence(of, traversable) { - return traverse(of, identity, traversable); + function sequence(typeRep, traversable) { + return traverse(typeRep, identity, traversable); } //# extend :: Extend w => (w a -> b, w a) -> w b diff --git a/package.json b/package.json index 8918565..9943345 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "devDependencies": { "doctest": "0.10.x", "eslint": "2.9.x", - "fantasy-land": "2.2.0", + "fantasy-land": "3.0.0", "istanbul": "0.4.x", "mocha": "2.x.x", "remember-bower": "0.1.x", diff --git a/test/Identity.js b/test/Identity.js index e245e6e..b6f2e28 100644 --- a/test/Identity.js +++ b/test/Identity.js @@ -39,7 +39,7 @@ Identity.prototype[FL.reduce] = function(f, x) { return f(x, this.value); }; -Identity.prototype[FL.traverse] = function(f, of) { +Identity.prototype[FL.traverse] = function(typeRep, f) { return Z.map(Identity, f(this.value)); }; diff --git a/test/List.js b/test/List.js index 5cb08bc..c830687 100644 --- a/test/List.js +++ b/test/List.js @@ -73,10 +73,10 @@ List.prototype[FL.reduce] = function(f, x) { Z.reduce(f, f(x, this.head), this.tail); }; -List.prototype[FL.traverse] = function(f, of) { +List.prototype[FL.traverse] = function(typeRep, f) { return this.tag === 'Nil' ? - of(Nil) : - Z.ap(Z.map(curry2(Cons), f(this.head)), Z.traverse(of, f, this.tail)); + Z.of(typeRep, Nil) : + Z.ap(Z.map(curry2(Cons), f(this.head)), Z.traverse(typeRep, f, this.tail)); }; List.prototype.inspect = diff --git a/test/index.js b/test/index.js index 586c51d..db10dda 100644 --- a/test/index.js +++ b/test/index.js @@ -19,24 +19,12 @@ var Nothing = Maybe.Nothing; var Just = Maybe.Just; -// Array$of :: a -> Array a -function Array$of(x) { - eq(arguments.length, Array$of.length); - return Z.of(Array, x); -} - // Lazy$of :: a -> Lazy a function Lazy$of(x) { eq(arguments.length, Lazy$of.length); return Z.of(Lazy, x); } -// List$of :: a -> List a -function List$of(x) { - eq(arguments.length, List$of.length); - return Z.of(List, x); -} - // abs :: Number -> Number function abs(x) { eq(arguments.length, abs.length); @@ -772,15 +760,15 @@ test('traverse', function() { eq(Z.traverse.length, 3); eq(Z.traverse.name, 'traverse'); - eq(Z.traverse(Array$of, identity, []), [[]]); - eq(Z.traverse(Array$of, identity, [[1], [2], [3]]), [[1, 2, 3]]); - eq(Z.traverse(Array$of, identity, [[1, 2, 3], [4, 5]]), [[1, 4], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5]]); - eq(Z.traverse(Array$of, identity, repeat(6)(range(10))).length, Math.pow(10, 6)); + eq(Z.traverse(Array, identity, []), [[]]); + eq(Z.traverse(Array, identity, [[1], [2], [3]]), [[1, 2, 3]]); + eq(Z.traverse(Array, identity, [[1, 2, 3], [4, 5]]), [[1, 4], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5]]); + eq(Z.traverse(Array, identity, repeat(6)(range(10))).length, Math.pow(10, 6)); eq(Z.traverse(Identity, identInc, []), Identity([])); eq(Z.traverse(Identity, identInc, [1, 2, 3]), Identity([2, 3, 4])); eq(Z.traverse(Identity, identInc, Nil), Identity(Nil)); eq(Z.traverse(Identity, identInc, Cons(1, Cons(2, Cons(3, Nil)))), Identity(Cons(2, Cons(3, Cons(4, Nil))))); - eq(Z.traverse(Lazy$of, Lazy$of, range(70000)).run().length, 70000); + eq(Z.traverse(Lazy, Lazy$of, range(70000)).run().length, 70000); }); test('sequence', function() { @@ -789,12 +777,12 @@ test('sequence', function() { eq(Z.sequence(Identity, []), Identity([])); eq(Z.sequence(Identity, [Identity(1), Identity(2), Identity(3)]), Identity([1, 2, 3])); - eq(Z.sequence(Array$of, Identity([])), []); - eq(Z.sequence(Array$of, Identity([1, 2, 3])), [Identity(1), Identity(2), Identity(3)]); + eq(Z.sequence(Array, Identity([])), []); + eq(Z.sequence(Array, Identity([1, 2, 3])), [Identity(1), Identity(2), Identity(3)]); eq(Z.sequence(Identity, Nil), Identity(Nil)); eq(Z.sequence(Identity, Cons(Identity(1), Cons(Identity(2), Cons(Identity(3), Nil)))), Identity(Cons(1, Cons(2, Cons(3, Nil))))); - eq(Z.sequence(List$of, Identity(Nil)), Nil); - eq(Z.sequence(List$of, Identity(Cons(1, Cons(2, Cons(3, Nil))))), Cons(Identity(1), Cons(Identity(2), Cons(Identity(3), Nil)))); + eq(Z.sequence(List, Identity(Nil)), Nil); + eq(Z.sequence(List, Identity(Cons(1, Cons(2, Cons(3, Nil))))), Cons(Identity(1), Cons(Identity(2), Cons(Identity(3), Nil)))); }); test('extend', function() {