Created
February 4, 2015 14:59
-
-
Save tonymorris/12029149ab4c876106c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Funcs { | |
public static class Funcs { | |
public static Func<A, C> Select<A, B, C>(this Func<A, B> f, Func<B, C> g) { | |
return a => g(f(a)); | |
} | |
public static Func<C, B> SelectMany<A, B, C>(this Func<C, A> f, Func<A, Func<C, B>> g) { | |
return a => g(f(a))(a); | |
} | |
public static Func<C, D> SelectMany<A, B, C, D>(this Func<C, A> f, Func<A, Func<C, B>> p, Func<A, B, D> k) { | |
return SelectMany<A, D, C>(f, b => Select<C, B, D>(p(b), x => k(b, x))); | |
} | |
} | |
class UseFunc { | |
Func< | |
Func<A, B, C> | |
, Func<int, A> | |
, Func<int, B> | |
, Func<int, C> | |
> | |
use<A, B, C>() { | |
return | |
(f, a, b) => | |
from aa in a | |
from bb in b | |
select f(aa, bb); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment