Skip to content

Commit e732768

Browse files
committed
simplify definitions of polymorphic functions
1 parent 37134e3 commit e732768

File tree

19 files changed

+238
-435
lines changed

19 files changed

+238
-435
lines changed

index.d.ts

Lines changed: 181 additions & 396 deletions
Large diffs are not rendered by default.

test-ts/alt.ts

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 9 additions & 9 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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'});

0 commit comments

Comments
 (0)