Skip to content

Commit

Permalink
pair :: (a -> b -> c) -> Pair a b -> c
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchambers committed Jan 17, 2022
1 parent 93f9159 commit 0aa7aae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions index.js
Expand Up @@ -150,6 +150,18 @@
};
}

//# Pair.pair :: (a -> b -> c) -> Pair a b -> c
//.
//. Case-folding function.
//.
//. `pair (f) (Pair (x) (y))` is equivalent to `f (x) (y)`.
//.
//. ```javascript
//. > Pair.pair (a => b => a + b) (Pair ('foo') ('bar'))
//. 'foobar'
//. ```
Pair.pair = f => p => f (p.fst) (p.snd);

//# Pair.fst :: Pair a b -> a
//.
//. `fst (Pair (x) (y))` is equivalent to `x`.
Expand Down
6 changes: 6 additions & 0 deletions test/index.js
Expand Up @@ -70,6 +70,12 @@ suite ('Pair', () => {
eq (iterator.next ()) ({value: undefined, done: true});
});

test ('Pair.pair', () => {
eq (Pair.pair (a => b => 'Pair (' + show (a) + ') (' + show (b) + ')')
(Pair ('abc') ([1, 2, 3])))
('Pair ("abc") ([1, 2, 3])');
});

test ('Pair.fst', () => {
eq (Pair.fst (Pair ('foo') (42))) ('foo');
});
Expand Down

0 comments on commit 0aa7aae

Please sign in to comment.