Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pair: add S.pair #609

Merged
merged 1 commit into from
Mar 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1992,6 +1992,25 @@
impl: Pair
};

//# pair :: (a -> b -> c) -> Pair a b -> c
//.
//. Case analysis for the `Pair a b` type.
//.
//. ```javascript
//. > S.pair (S.concat) (S.Pair ('foo') ('bar'))
//. 'foobar'
//. ```
function pair(f) {
return function(pair) {
return f (pair.fst) (pair.snd);
};
}
_.pair = {
consts: {},
types: [Fn (a) (Fn (b) (c)), $Pair (a) (b), c],
impl: pair
};

//# fst :: Pair a b -> a
//.
//. `fst (Pair (x) (y))` is equivalent to `x`.
Expand All @@ -2003,7 +2022,7 @@
_.fst = {
consts: {},
types: [$Pair (a) (b), a],
impl: Pair.fst
impl: pair (K)
};

//# snd :: Pair a b -> b
Expand All @@ -2017,7 +2036,7 @@
_.snd = {
consts: {},
types: [$Pair (a) (b), b],
impl: Pair.snd
impl: pair (C (K))
};

//# swap :: Pair a b -> Pair b a
Expand All @@ -2031,7 +2050,7 @@
_.swap = {
consts: {},
types: [$Pair (a) (b), $Pair (b) (a)],
impl: Pair.swap
impl: pair (C (Pair))
};

//. ### Maybe type
Expand Down
16 changes: 16 additions & 0 deletions test/pair~.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

const S = require ('..');

const eq = require ('./internal/eq');


test ('pair', () => {

eq (typeof S.pair) ('function');
eq (S.pair.length) (1);
eq (S.show (S.pair)) ('pair :: (a -> b -> c) -> Pair a b -> c');

eq (S.pair (S.concat) (S.Pair ('foo') ('bar'))) ('foobar');

});