Skip to content
This repository has been archived by the owner on Sep 9, 2023. It is now read-only.

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tkuminecz committed Dec 20, 2016
1 parent 4264b39 commit 9f5345e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/pair.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ export class Pair<A, B> {
}

/**
* `map :: Pair a b ~> ([a, b] -> [x, y]) -> Pair x y`
* `map :: Pair a b ~> (b -> c) -> Pair a c`
*
* Transforms the values in the `Pair` instance.
* Transforms the right (second) value in the `Pair` instance.
*/
map<X, Y>(f: (p: [A, B]) => [X, Y]): Pair<X, Y> {
return Pair.of(f(this.data));
map<C>(f: (b: B) => C): Pair<A, C> {
const [ a, b ] = this.data;
return Pair.of([ a, f(b) ]);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion test/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as Util from './test-util';
const ioMapper = <A>(ia: IO<A>): A => ia.runIO();

test('IO', t => {
t.plan(5);
t.plan(6);

const tIO = { t, mapper: ioMapper };

Expand All @@ -15,4 +15,6 @@ test('IO', t => {
Util.testLift(tIO, IO);
Util.testLift2(tIO, IO);
Util.testLift3(tIO, IO);

t.equal(IO.from(() => 42).runIO(), 42, 'IO.from');
});
9 changes: 6 additions & 3 deletions test/pair.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Pair } from '../src/pair';
import test from 'tape';

test('Pair', t => {
t.plan(4);
t.plan(7);

let pair = Pair.of([ 'foo', 42 ]);

Expand All @@ -18,9 +18,12 @@ test('Pair', t => {
);

t.deepEqual(
pair.map(([ s, n ]) => [s.toUpperCase(), n * 2]),
Pair.of([ 'FOO', 84 ]),
pair.map(n => n * 2),
Pair.of([ 'foo', 84 ]),
'Pair.map'
);

t.deepEqual(pair.toTuple(), [ 'foo', 42 ], 'pair.toTuple');
t.equal(pair.left(), 'foo', 'pair.left');
t.equal(pair.right(), 42, 'pair.right');
});

0 comments on commit 9f5345e

Please sign in to comment.