Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e732768

Browse files
committedOct 8, 2017
simplify definitions of polymorphic functions
1 parent 37134e3 commit e732768

19 files changed

+238
-435
lines changed
 

‎index.d.ts

+181-396
Large diffs are not rendered by default.

‎test-ts/alt.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ test('alt', () => {
1010
eq(S.alt.toString(), 'alt :: Alt f => f a -> f a -> f a');
1111

1212
eq(S.alt([])([]), []);
13-
const empty: number[] = []; // Microsoft/TypeScript#8944
14-
eq(S.alt(empty)([1, 2, 3]), [1, 2, 3]);
13+
eq(S.alt([])([1, 2, 3]), [1, 2, 3]);
1514
eq(S.alt([1, 2, 3])([]), [1, 2, 3]);
1615
eq(S.alt([1, 2, 3])([4, 5, 6]), [1, 2, 3, 4, 5, 6]);
1716
eq(S.alt({})({}), {});

‎test-ts/chain.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test('chain', () => {
99
eq(S.chain.length, 2);
1010
eq(S.chain.toString(), 'chain :: Chain m => (a -> m b) -> m a -> m b');
1111

12-
eq(S.chain<number[], number>(S.I)([[1, 2], [3, 4], [5, 6]]), [1, 2, 3, 4, 5, 6]);
12+
eq(S.chain(S.I)([[1, 2], [3, 4], [5, 6]]), [1, 2, 3, 4, 5, 6]);
1313
eq(S.chain(S.parseFloat)(S.Nothing), S.Nothing);
1414
eq(S.chain(S.parseFloat)(S.Just('X')), S.Nothing);
1515
eq(S.chain(S.parseFloat)(S.Just('0')), S.Just(0));

‎test-ts/concat.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ test('concat', () => {
1111

1212
eq(S.concat([])([]), []);
1313
eq(S.concat([1, 2, 3])([]), [1, 2, 3]);
14-
eq(S.concat<number>([])([4, 5, 6]), [4, 5, 6]);
14+
eq(S.concat([])([4, 5, 6]), [4, 5, 6]);
1515
eq(S.concat([1, 2, 3])([4, 5, 6]), [1, 2, 3, 4, 5, 6]);
1616

1717
eq(S.concat('')(''), '');
1818
eq(S.concat('foo')(''), 'foo');
1919
eq(S.concat('')('bar'), 'bar');
2020
eq(S.concat('foo')('bar'), 'foobar');
2121

22-
eq(S.concat<S.Maybe<string>>(S.Nothing)(S.Nothing), S.Nothing);
22+
eq(S.concat(S.Nothing)(S.Nothing), S.Nothing);
2323
eq(S.concat(S.Just('foo'))(S.Nothing), S.Just('foo'));
2424
eq(S.concat(S.Nothing)(S.Just('bar')), S.Just('bar'));
2525
eq(S.concat(S.Just('foo'))(S.Just('bar')), S.Just('foobar'));

‎test-ts/groupBy.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ test('groupBy', () => {
2525

2626
eq(S.groupBy(productsOf3)([]), []);
2727
eq(S.groupBy(productsOf3)([1, 2, 3, 4, 5, 6, 7, 8, 9]), [[1], [2, 3], [4], [5, 6], [7], [8, 9]]);
28-
eq(S.groupBy<number>(S.equals)([1, 1, 2, 1, 1]), [[1, 1], [2], [1, 1]]);
28+
eq(S.groupBy(S.equals)([1, 1, 2, 1, 1]), [[1, 1], [2], [1, 1]]);
2929
eq(S.groupBy(zeroSum)([2, -3, 3, 3, 3, 4, -4, 4]), [[2], [-3, 3, 3, 3], [4, -4], [4]]);
3030

31-
jsc.assert(jsc.forall('nat -> nat -> bool', 'array nat', function(f: (x: number) => (y: number) => boolean, xs: number[]) {
31+
jsc.assert(jsc.forall('nat -> nat -> bool', 'array nat', function(f: (x: number) => (y: number) => boolean, xs: Array<number>) {
3232
return S.equals(S.join(S.groupBy(f)(xs)))(xs);
3333
}), {tests: 100});
3434

‎test-ts/on.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ test('on', () => {
1111
eq(S.on.toString(), 'on :: (b -> b -> c) -> (a -> b) -> a -> a -> c');
1212

1313
eq(S.on(rem)(S.prop('x'))({x: 5, y: 5})({x: 3, y: 3}), 2);
14-
eq(S.on(S.concat)(S.reverse)([1, 2, 3])([4, 5, 6]), [3, 2, 1, 6, 5, 4]);
14+
eq(S.on<Array<number>, Array<number>, Array<number>>(S.concat)(S.reverse)([1, 2, 3])([4, 5, 6]), [3, 2, 1, 6, 5, 4]);
1515

1616
});

‎test-ts/reduce.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ test('reduce', () => {
1515
eq(S.reduce(S.concat)('x')({a: 'A', b: 'B', c: 'C'}), 'xABC');
1616
eq(S.reduce(S.concat)('x')({c: 'C', b: 'B', a: 'A'}), 'xABC');
1717
eq(S.reduce(S.concat)('x')(S.Just('A')), 'xA');
18-
eq(S.reduce(S.lift2<string, string, string>(S.concat))(S.Just('x'))([S.Just('A'), S.Just('B'), S.Just('C')]), S.Just('xABC'));
18+
eq(S.reduce(S.lift2(S.concat))(S.Just('x'))([S.Just('A'), S.Just('B'), S.Just('C')]), S.Just('xABC'));
1919

2020
});

‎test-ts/traverse.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as S from '..';
1+
const S = require('../test/internal/sanctuary');
22

33
import Identity from './internal/Identity';
44
import eq from './internal/eq';
@@ -17,19 +17,19 @@ test('traverse', () => {
1717
eq(S.traverse(S.Maybe)(S.parseInt(16))({a: 'A', b: 'B', c: 'C'}), S.Just({a: 10, b: 11, c: 12}));
1818
eq(S.traverse(S.Maybe)(S.parseInt(16))({a: 'A', b: 'B', c: 'C', x: 'X'}), S.Nothing);
1919

20-
eq(S.traverse(Array)<Array<string>, string>(S.I)([]), [[]]);
21-
eq(S.traverse(Array)<Array<string>, string>(S.I)([['A', 'a']]), [['A'], ['a']]);
22-
eq(S.traverse(Array)<Array<string>, string>(S.I)([['A', 'a'], ['B']]), [['A', 'B'], ['a', 'B']]);
23-
eq(S.traverse(Array)<Array<string>, string>(S.I)([['A', 'a'], ['B', 'b']]), [['A', 'B'], ['A', 'b'], ['a', 'B'], ['a', 'b']]);
20+
eq(S.traverse(Array)(S.I)([]), [[]]);
21+
eq(S.traverse(Array)(S.I)([['A', 'a']]), [['A'], ['a']]);
22+
eq(S.traverse(Array)(S.I)([['A', 'a'], ['B']]), [['A', 'B'], ['a', 'B']]);
23+
eq(S.traverse(Array)(S.I)([['A', 'a'], ['B', 'b']]), [['A', 'B'], ['A', 'b'], ['a', 'B'], ['a', 'b']]);
2424

2525
eq(S.traverse(Array)(S.words)(of('')), []);
2626
eq(S.traverse(Array)(S.words)(of('foo')), [of('foo')]);
2727
eq(S.traverse(Array)(S.words)(of('foo bar')), [of('foo'), of('bar')]);
2828
eq(S.traverse(Array)(S.words)(of('foo bar baz')), [of('foo'), of('bar'), of('baz')]);
2929

30-
eq(S.traverse(Identity)<S.Applicative<number>, number>(S.I)([]), of([]));
31-
eq(S.traverse(Identity)<S.Applicative<number>, number>(S.I)([of(1)]), of([1]));
32-
eq(S.traverse(Identity)<S.Applicative<number>, number>(S.I)([of(1), of(2)]), of([1, 2]));
33-
eq(S.traverse(Identity)<S.Applicative<number>, number>(S.I)([of(1), of(2), of(3)]), of([1, 2, 3]));
30+
eq(S.traverse(Identity)(S.I)([]), of([]));
31+
eq(S.traverse(Identity)(S.I)([of(1)]), of([1]));
32+
eq(S.traverse(Identity)(S.I)([of(1), of(2)]), of([1, 2]));
33+
eq(S.traverse(Identity)(S.I)([of(1), of(2), of(3)]), of([1, 2, 3]));
3434

3535
});

‎test/typescript/append.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import {append} from '../..';
33
// $ExpectType number[]
44
append(3)([1, 2]);
55

6-
// $ExpectError Argument of type 'number[]' is not assignable to parameter of type 'string[]'.
6+
// $ExpectType Applicative<string>
77
append('foo')([1, 2]);

‎test/typescript/elem.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ elem('foo')(['foo', 'bar']);
66
// $ExpectType boolean
77
elem('foo')({a: 'foo', b: 'bar'});
88

9-
// $ExpectError Argument of type 'string[]' is not assignable to parameter of type 'number[] | Foldable<number> | StrMap<number>'.
9+
// $ExpectType boolean
1010
elem(1)(['foo', 'bar']);
1111

12-
// $ExpectError Argument of type '{ a: string; b: string; }' is not assignable to parameter of type 'number[] | Foldable<number> | StrMap<number>'.
12+
// $ExpectType boolean
1313
elem(1)({a: 'foo', b: 'bar'});

‎test/typescript/filterM.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ filterM(odd)([1, 2, 3]);
99
// $ExpectError Argument of type '(n: number) => 0' is not assignable to parameter of type 'Predicate<number>'.
1010
filterM((n: number) => 0)([1, 2, 3]);
1111

12-
// $ExpectType Maybe<number>
12+
// $ExpectType Foldable<number>
1313
filterM(odd)(Nothing);
1414

15-
// $ExpectType Maybe<number>
15+
// $ExpectType Foldable<number>
1616
filterM(odd)(Just(1));

‎test/typescript/find.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import {find, odd} from '../..';
33
// $ExpectType Maybe<number>
44
find(odd)([1, 2, 3]);
55

6-
// $ExpectError Argument of type 'string[]' is not assignable to parameter of type 'number[] | Foldable<number> | StrMap<number>'.
6+
// $ExpectType Maybe<number>
77
find(odd)(['foo', 'bar']);

‎test/typescript/map.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ map(mult(2))([1, 2, 3]);
1212
// $ExpectError The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
1313
map(n => n * 2)(['foo', 1, 2]);
1414

15-
// $ExpectError Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'.
15+
// $ExpectType Functor<number>
1616
map(mult(2))(['foo', 1, 2]);
1717

1818
// TODO: Add tests using Maybe, Either, Functor, placeholder params

‎test/typescript/pipe.ts

+26-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
1-
import {add, sub, pipe} from '../..';
1+
import {add, pipe} from '../..';
22

3-
// $ExpectType any
4-
pipe([add(1), sub(1)])(10);
3+
// $ExpectType {}
4+
pipe([])(0);
55

6-
// $ExpectType any
7-
pipe([add(1), sub(1)])('x');
6+
// $ExpectType number
7+
pipe([add(1)])(0);
8+
9+
// $ExpectType number
10+
pipe([add(1), add(1)])(0);
11+
12+
// $ExpectType number
13+
pipe([add(1), add(1), add(1)])(0);
14+
15+
// $ExpectType number
16+
pipe([add(1), add(1), add(1), add(1)])(0);
17+
18+
// $ExpectType number
19+
pipe([add(1), add(1), add(1), add(1), add(1)])(0);
20+
21+
// $ExpectType number
22+
pipe([add(1), add(1), add(1), add(1), add(1), add(1)])(0);
23+
24+
// $ExpectType number
25+
pipe([add(1), add(1), add(1), add(1), add(1), add(1), add(1)])(0);
26+
27+
// $ExpectType string
28+
pipe([(s: string) => s.length, add(1), add(1), (n: number) => n.toFixed(2)])('');

‎test/typescript/pluck.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {pluck} from '../..';
22

3-
// $ExpectType any[]
3+
// $ExpectType Functor<any>
44
pluck('x')([{x: 1}, {x: 2, y: 3}]);
55

6-
// $ExpectType any[]
6+
// $ExpectType Functor<any>
77
pluck('x')([{x: 'foo'}, {x: 'bar', y: 'baz'}]);

‎test/typescript/prepend.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import {prepend} from '../..';
33
// $ExpectType number[]
44
prepend(3)([1, 2]);
55

6-
// $ExpectError Argument of type 'number[]' is not assignable to parameter of type 'string[]'.
6+
// $ExpectType Applicative<string>
77
prepend('foo')([1, 2]);

‎test/typescript/reduce.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Just, Nothing, add, concat, reduce} from '../..';
1+
import {Just, Nothing, add, reduce} from '../..';
22

33
// $ExpectType number
44
reduce(add)(0)([1, 2, 3]);
@@ -7,9 +7,9 @@ reduce(add)(0)([1, 2, 3]);
77
reduce((s1: string) => s2 => s1 + s2)('a')(['b', 'c']);
88

99
// $ExpectType string[]
10-
reduce((a1: string[]) => a2 => concat(a1)(a2))([])([['a'], [], ['b', 'c']]);
10+
reduce((a1: Array<string>) => a2 => a1.concat(a2))([])([['a'], [], ['b', 'c']]);
1111

12-
// $ExpectError Argument of type '(string | number)[]' is not assignable to parameter of type 'number[] | Maybe<number> | Foldable<number> | StrMap<number> | Either<{}, number>'.
12+
// $ExpectType number
1313
reduce(add)(0)([1, 'foo', 3]);
1414

1515
// TODO: Placeholder tests, foldable tests, curried version tests, type error tests

‎test/typescript/reverse.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import {reverse} from '../..';
22

3-
// $ExpectType string
4-
reverse('foo');
5-
63
// $ExpectType number[]
74
reverse([1, 2, 3]);
85

‎tslint.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"space-before-function-paren": false,
99
"typedef-whitespace": false,
1010
"unified-signatures": false,
11+
"variable-name": false,
1112
"whitespace": false
1213
}
1314
}

0 commit comments

Comments
 (0)
Please sign in to comment.