Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Created February 4, 2015 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tonymorris/12029149ab4c876106c7 to your computer and use it in GitHub Desktop.
Save tonymorris/12029149ab4c876106c7 to your computer and use it in GitHub Desktop.
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