Skip to content

Commit

Permalink
Include function name in type sig
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Christopher committed Feb 3, 2016
1 parent 3f4135d commit b74cac2
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 85 deletions.
20 changes: 10 additions & 10 deletions src/Cons.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,44 @@ const
Tuple = RF.Tuple;


//:: Prism [a] [b] (a, [a]) (b, [b])
// _Cons :: Prism [a] [b] (a, [a]) (b, [b])
const _Cons = Prism.prism(
t => R.prepend(Tuple.fst(t), Tuple.snd(t)),
R.ifElse(R.isEmpty,
Either.Left,
xss => Either.Right(Tuple(R.head(xss), R.tail(xss)))));

//:: Prism [a] [b] ([a], a) ([b], b)
// _Snoc :: Prism [a] [b] ([a], a) ([b], b)
const _Snoc = Prism.prism(
t => R.append(Tuple.snd(t), Tuple.fst(t)),
R.ifElse(R.isEmpty,
Either.Left,
xss => Either.Right(Tuple(R.init(xss), R.last(xss)))));

//:: a -> [a] -> [a]
// cons :: a -> [a] -> [a]
const cons = R.curry((x, xs) =>
Prism.review(_Cons, Tuple(x, xs)));

//:: [a] -> Maybe (Tuple a [a])
// uncons :: [a] -> Maybe (Tuple a [a])
const uncons = Fold.preview(_Cons);

//:: [a] -> a -> [a]
// snoc :: [a] -> a -> [a]
const snoc = R.curry((xs, x) =>
Prism.review(_Snoc, Tuple(xs, x)));

//:: [a] -> Maybe (Tuple [a] a)
// unsnoc :: [a] -> Maybe (Tuple [a] a)
const unsnoc = Fold.preview(_Snoc);

//:: TraversalP s a
// _head :: TraversalP s a
const _head = Category.compose(_Cons, Lens._1);

//:: TraversalP s s
// _tail :: TraversalP s s
const _tail = Category.compose(_Cons, Lens._2);

//:: TraversalP s a
// _init :: TraversalP s a
const _init = Category.compose(_Snoc, Lens._1);

//:: TraversalP s s
// _last :: TraversalP s s
const _last = Category.compose(_Snoc, Lens._2);

module.exports = {
Expand Down
50 changes: 25 additions & 25 deletions src/Fold.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,103 +22,103 @@ const

const Unit = {};

//:: Apply f => f a -> f b -> f b -- (*>)
// _apR :: Apply f => f a -> f b -> f b -- (*>)
const _apR = R.curry((lAp, rAp) =>
lAp.map(_ => R.identity).ap(rAp));

//:: Monoid m => Type m -> Fold m s t a b -> (a -> m) -> s -> m
// foldMapOf :: Monoid m => Type m -> Fold m s t a b -> (a -> m) -> s -> m
const foldMapOf = R.curry((M, p, f, s) =>
p(Forget(M)(f)).runForget(s));

//:: Monoid m => Type m -> Fold m s t m b -> s -> m
// foldOf :: Monoid m => Type m -> Fold m s t m b -> s -> m
const foldOf = R.curry((M, p, s) =>
p(Forget(M)(x => x)).runForget(s));

//:: Fold (First a) s t a b -> s -> Maybe a
// preview :: Fold (First a) s t a b -> s -> Maybe a
const preview = R.curry((p, s) =>
foldMapOf(First, p, R.compose(First, Maybe.Just), s).first);

//:: Fold (Endo r) s t a b -> (a -> r -> r) -> r -> s -> r
// foldrOf :: Fold (Endo r) s t a b -> (a -> r -> r) -> r -> s -> r
const foldrOf = R.curry((p, f, r, s) =>
foldMapOf(Endo, p, x => Endo(f(x)), s).runEndo(r));

//:: Fold (Dual (Endo r)) s t a b -> (r -> a -> r) -> r -> s -> r
// foldlOf :: Fold (Dual (Endo r)) s t a b -> (r -> a -> r) -> r -> s -> r
const foldlOf = R.curry((p, f, r, s) =>
foldMapOf(Dual(Endo), p, R.compose(Dual(Endo), Endo, R.flip(f)), s).dual.runEndo(r));

//:: Fold (Conj Boolean) s t a b -> (a -> Boolean) -> s -> Boolean
// allOf :: Fold (Conj Boolean) s t a b -> (a -> Boolean) -> s -> Boolean
const allOf = R.curry((p, f, s) =>
foldMapOf(Conj, p, R.compose(Conj, f), s).toBool);

//:: Fold (Disj Boolean) s t a b -> (a -> Boolean) -> s -> Boolean
// anyOf :: Fold (Disj Boolean) s t a b -> (a -> Boolean) -> s -> Boolean
const anyOf = R.curry((p, f, s) =>
foldMapOf(Disj, p, R.compose(Disj, f), s).toBool);

//:: Fold (Conj Boolean) s t Boolean b -> s -> Boolean
// andOf :: Fold (Conj Boolean) s t Boolean b -> s -> Boolean
const andOf = R.curry((p, s) => allOf(p, R.identity, s));

//:: Fold (Disj Boolean) s t Boolean b -> s -> Boolean
// orOf :: Fold (Disj Boolean) s t Boolean b -> s -> Boolean
const orOf = R.curry((p, s) => anyOf(p, R.identity, s));

//:: Eq a => Fold (Disj Boolean) s t a b -> a -> s -> Boolean
// elemOf :: Eq a => Fold (Disj Boolean) s t a b -> a -> s -> Boolean
const elemOf = R.curry((p, a, s) =>
anyOf(p, R.equals(a), s));

//:: Eq a => Fold (Conj Boolean) s t a b -> a -> s -> Boolean
// notElemOf :: Eq a => Fold (Conj Boolean) s t a b -> a -> s -> Boolean
const notElemOf = R.curry((p, a, s) =>
allOf(p, x => !R.equals(a, x), s));

//:: Fold (Additive Number) s t Number b -> s -> Number
// sumOf :: Fold (Additive Number) s t Number b -> s -> Number
const sumOf = R.curry((p, s) =>
foldMapOf(Additive, p, Additive, s).toNum);

//:: Fold (Multiplicative Number) s t Number b -> s -> Number
// productOf :: Fold (Multiplicative Number) s t Number b -> s -> Number
const productOf = R.curry((p, s) =>
foldMapOf(Multiplicative, p, Multiplicative, s).toNum);

//:: Fold (Additive Int) s t a b -> s -> Int
// lengthOf :: Fold (Additive Int) s t a b -> s -> Int
const lengthOf = R.curry((p, s) =>
foldMapOf(Additive, p, () => Additive(1), s).toNum);

//:: Fold (First a) s t a b -> s -> Maybe a
// firstOf :: Fold (First a) s t a b -> s -> Maybe a
const firstOf = R.curry((p, s) =>
foldMapOf(First, p, R.compose(First, Maybe.Just), s).first);

//:: Fold (Last a) s t a b -> s -> Maybe a
// lastOf :: Fold (Last a) s t a b -> s -> Maybe a
const lastOf = R.curry((p, s) =>
foldMapOf(Last, p, R.compose(Last, Maybe.Just), s).last);

//:: Ord a => Fold (Endo (Maybe a)) s t a b -> s -> Maybe a
// maximumOf :: Ord a => Fold (Endo (Maybe a)) s t a b -> s -> Maybe a
const maximumOf = R.curry((p, s) =>
foldrOf(p, R.curry((a, m) => Maybe.Just(Maybe.maybe(a, R.max(a), m))), Maybe.Nothing(), s));

//:: Ord a => Fold (Endo (Maybe a)) s t a b -> s -> Maybe a
// minimumOf :: Ord a => Fold (Endo (Maybe a)) s t a b -> s -> Maybe a
const minimumOf = R.curry((p, s) =>
foldrOf(p, a => m => Maybe.Just(Maybe.maybe(a, R.min(a), m)), Maybe.Nothing(), s));

//:: Fold (Endo (Maybe a)) s t a b -> (a -> Boolean) -> s -> Maybe a
// findOf :: Fold (Endo (Maybe a)) s t a b -> (a -> Boolean) -> s -> Maybe a
const findOf = R.curry((p, f, s) =>
foldlOf(p, R.curry((m, a) => m.isJust ? m
: f(a) ? Maybe.Just(a)
: Maybe.Nothing()), Maybe.Nothing(), s));

//:: Applicative f => Type f -> Fold (Endo (f Unit)) s t (f a) b -> s -> f Unit
// sequenceOf_ :: Applicative f => Type f -> Fold (Endo (f Unit)) s t (f a) b -> s -> f Unit
const sequenceOf_ = R.curry((fType, p, s) =>
foldMapOf(Endo, p, R.compose(Endo, _apR), s).runEndo(fType.of(Unit)));

//:: Fold (Endo [a]) s t a b -> s -> [a]
// toListOf :: Fold (Endo [a]) s t a b -> s -> [a]
const toListOf = R.curry((p, s) =>
foldrOf(p, R.prepend, [], s));

//:: Fold (Disj Boolean) s t a b -> s -> Boolean
// has :: Fold (Disj Boolean) s t a b -> s -> Boolean
const has = R.curry((p, s) =>
foldMapOf(Disj, p, () => Disj(true), s).toBool);

//:: Fold (Conj Boolean) s t a b -> s -> Boolean
// hasnt :: Fold (Conj Boolean) s t a b -> s -> Boolean
const hasnt = R.curry((p, s) =>
foldMapOf(Conj, p, () => Conj(false), s).toBool);

//:: Choice p => (a -> Boolean) -> OpticP p a a
// filtered :: Choice p => (a -> Boolean) -> OpticP p a a
const filtered = R.curry((f, c) =>
Profunctor.dimap(R.ifElse(f, Either.Right, Either.Left), e => e.value, Choice.right(c)));

Expand Down
2 changes: 1 addition & 1 deletion src/Getter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const
UnitM = require('./Internal/Monoid/Unit');


//:: Getter s t a b -> s -> a
// view :: Getter s t a b -> s -> a
const view = Fold.foldOf(UnitM);

module.exports = {
Expand Down
6 changes: 3 additions & 3 deletions src/Internal/Category.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//:: Category a => Type a -> a b b
// id :: Category a => Type a -> a b b
const id = Category =>
Category === Function ? (x => x) : Category.id;

//:: Semigroupoid a => a c d -> a b c -> a b d
// compose :: Semigroupoid a => a c d -> a b c -> a b d
const compose = (f, g) => {
if (typeof f.compose === 'function') return f.compose(g);
if (typeof f === 'function' && typeof g === 'function') return x => f(g(x));
throw new TypeError('Expected Semigroupoid');
};

//:: Semigroupoid a => a b c -> a c d -> a b d
// pipe :: Semigroupoid a => a b c -> a c d -> a b d
const pipe = (f, g) => compose(g, f);

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Const.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const R = require('ramda');


//:: Monoid m => Type m -> a -> Const a b
// _Const :: Monoid m => Type m -> a -> Const a b
const _Const = M => {
function Const(x) {
return {
Expand Down
8 changes: 4 additions & 4 deletions src/Internal/Profunctor/Class/Choice.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ const
Either = RF.Either;


//:: Choice p => p a b -> p (Either a c) (Either b c)
// left :: Choice p => p a b -> p (Either a c) (Either b c)
const left = pab => {
if (typeof pab.left === 'function') return pab.left();
if (typeof pab === 'function') return e => e.bimap(pab, x => x);
throw new TypeError('Expected Choice instance');
};

//:: Choice p => p b c -> p (Either a b) (Either a c)
// right :: Choice p => p b c -> p (Either a b) (Either a c)
const right = pbc => {
if (typeof pbc.right === 'function') return pbc.right();
if (typeof pbc === 'function') return e => e.map(pbc);
throw new TypeError('Expected Choice instance');
};

//:: Category p, Choice p => p a b -> p c d -> p (Either a c) (Either b d)
// choice :: Category p, Choice p => p a b -> p c d -> p (Either a c) (Either b d)
const choice = R.curry((c1, c2) => C.pipe(left(c1), right(c2)));

//:: Category p, Choice p => p a c -> p b c -> p (Either a b) c
// join :: Category p, Choice p => p a c -> p b c -> p (Either a b) c
const join = R.curry((Cat, l, r) =>
C.pipe(choice(l, r),
PF.lmap(Either.either(x => x, x => x),
Expand Down
8 changes: 4 additions & 4 deletions src/Internal/Profunctor/Class/Profunctor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ const
C = require('../../Category');


//:: Profunctor p => (a -> b) -> (c -> d) -> p b c -> p a d
// dimap :: Profunctor p => (a -> b) -> (c -> d) -> p b c -> p a d
const dimap = R.curry((a2b, c2d, pbc) => {
if (typeof pbc.dimap === 'function') return pbc.dimap(a2b, c2d);
if (typeof pbc === 'function') return a => c2d(pbc(a2b(a)));
throw new TypeError('Expected Profunctor');
});

//:: Profunctor p => (a -> b) -> p b c -> p a c
// lmap :: Profunctor p => (a -> b) -> p b c -> p a c
const lmap = R.curry((a2b, pbc) => {
if (typeof pbc.lmap === 'function') return pbc.lmap(a2b);
if (typeof pbc.dimap === 'function') return dimap(a2b, x => x, pbc);
if (typeof pbc === 'function') return a => pbc(a2b(a));
throw new TypeError('Expected Profunctor');
});

//:: Profunctor p => (b -> c) -> p a b -> p a c
// rmap :: Profunctor p => (b -> c) -> p a b -> p a c
const rmap = R.curry((b2c, pab) => {
if (typeof pab.rmap === 'function') return pab.rmap(b2c);
if (typeof pab.dimap === 'function') return dimap(x => x, b2c, pab);
if (typeof pab === 'function') return a => b2c(pab(a));
throw new TypeError('Expected Profunctor');
});

//:: Category p, Profunctor p => (a -> b) -> p a b
// arr :: Category p, Profunctor p => (a -> b) -> p a b
const arr = R.curry((Cat, f) => rmap(f, C.id(Cat)));

module.exports = {
Expand Down
8 changes: 4 additions & 4 deletions src/Internal/Profunctor/Class/Strong.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ const
Tuple = RF.Tuple;


//:: Strong p => p a c -> p (Tuple a b) (Tuple c b)
// first :: Strong p => p a c -> p (Tuple a b) (Tuple c b)
const first = p => {
if (typeof p.first === 'function') return p.first();
if (typeof p === 'function') return t => Tuple(p(Tuple.fst(t)), Tuple.snd(t));
throw new TypeError('Expected Strong instance');
};

//:: Strong p => p b c -> p (Tuple a b) (Tuple a c)
// second :: Strong p => p b c -> p (Tuple a b) (Tuple a c)
const second = p => {
if (typeof p.second === 'function') return p.second();
if (typeof p === 'function') return R.map(p);
throw new TypeError('Expected Strong instance');
};

//:: Category p, Strong p => p a b -> p c d -> p (Tuple a c) (Tuple b d)
// both :: Category p, Strong p => p a b -> p c d -> p (Tuple a c) (Tuple b d)
const both = R.curry((p1, p2) => C.pipe(first(p1), second(p2)));

//:: Category p, Strong p => Type p -> p a b -> p a c -> p a (Tuple b c)
// split :: Category p, Strong p => Type p -> p a b -> p a c -> p a (Tuple b c)
const split = R.curry((Cat, l, r) =>
C.pipe(PF.rmap(a => Tuple(a, a), C.id(Cat)),
both(l, r)));
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Profunctor/Class/Wander.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const
Identity = RF.Identity;


//:: Applicative f => ((a -> f a) -> (a -> f b) -> s -> f t) -> p a b -> p s t
// wander :: Applicative f => ((a -> f a) -> (a -> f b) -> s -> f t) -> p a b -> p s t
const wander = R.curry((t, p) => {
if (typeof p.wander === 'function') return p.wander(t);
if (typeof p === 'function') return s => t(Identity, a => Identity(p(a)), s).value;
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Profunctor/Exchange.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//:: (s -> a) -> (b -> t) -> Exchange a b s t
// Exchange :: (s -> a) -> (b -> t) -> Exchange a b s t
const Exchange = (s2a, b2t) => ({
runTo: s2a,
runFro: b2t,
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Profunctor/Forget.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const

// `Forget` is a `Profunctor` that ignores its covariant type.
//
//:: Monoid m => Type m -> (a -> r) -> Forget r a b
// _Forget :: Monoid m => Type m -> (a -> r) -> Forget r a b
const _Forget = M => function Forget(z) {
return {
runForget: z,
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Profunctor/Re.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const
Profunctor = require('./Class/Profunctor');


//:: Profunctor p => (p b a -> p t s) -> Re p s t a b
// Re :: Profunctor p => (p b a -> p t s) -> Re p s t a b
const Re = r => ({
runRe: r,
dimap: (f, g) => Re(p => r(Profunctor.dimap(g, f, p)))
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Profunctor/Star.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const
// `Star` lifts a `Functor` into a `Profunctor`. The `Applicative` constraint is
// only necessary to implement `Choice` and `Wander`.
//
//:: Applicative f => Type f -> (a -> f b) -> Star f a b
// _Star :: Applicative f => Type f -> (a -> f b) -> Star f a b
const _Star = F => function Star(afb) {
return {
runStar: afb,
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Profunctor/Tagged.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const

// `Tagged` is a `Profunctor` that ignores its contravariant type.
//
//:: b -> Tagged a b
// Tagged :: b -> Tagged a b
const Tagged = b => ({
unTagged: b,
dimap: (_, g) => Tagged(g(b)),
Expand Down
Loading

0 comments on commit b74cac2

Please sign in to comment.