Created
February 28, 2017 06:37
-
-
Save afifmohammed/6eaa055a216eef36822ff2b6b97e1b21 to your computer and use it in GitHub Desktop.
reader spik
This file contains hidden or 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
void Main() | |
{ | |
var id = new Id(); | |
Func<Id, Customer> customerById = x => new Customer(); | |
Func<Criteria, CreditHistory> creditHistoryByCriteria = x => new CreditHistory(); | |
Func<Report, Unit> print = x => new Unit(); | |
var history = GetCustomer(id) | |
.Map(GetCustomerCreditHistory) | |
.Uncurry() | |
.Map(PrintReport) | |
(customerById, creditHistoryByCriteria) | |
(print); | |
} | |
Func<Func<Criteria, CreditHistory>, CreditHistory> GetCustomerCreditHistory(Customer customer) => | |
getCreditHistory => getCreditHistory(new Criteria {Context = customer.ToString()}) | |
Func<Func<Id, Customer>, Customer> GetCustomer(Id id) => | |
getCustomer => getCustomer(id); | |
Func<Func<Report, Unit>, Unit> PrintReport(CreditHistory r) => print => | |
print(new Report(r)); | |
public static class Ex | |
{ | |
public static Func<A, B, C> Uncurry<A, B, C>(this Func<A, Func<B,C>> f_a_f_b_c) => (a,b) => f_a_f_b_c(a)(b); | |
// (A<T>, T -> R) -> A<R> | |
// where A : Func<Env,_> | |
public static Func<Env,B> Map<Env, A, B>( | |
this Func<Env,A> fun_e_a, | |
Func<A, B> f_a_b) => | |
env => f_a_b(fun_e_a(env)); | |
public static Func<Env1, Env2, B> Map<Env1, Env2, A, B>( | |
this Func<Env1, Env2, A> fun_e_a, | |
Func<A, B> f_a_b) => | |
(env1, env2) => f_a_b(fun_e_a(env1, env2)); | |
// (A<T>, T -> A<R>) -> A<R> | |
// where A : Func<Env,_> | |
public static Func<Env, B> Bind<Env, A, B>( | |
this Func<Env, A> fun_e_a, | |
Func<A, Func<Env,B>> f_a_f_e_b) => | |
env => f_a_f_e_b(fun_e_a(env))(env); | |
public static Func<Env, C> Bind<Env, A, B, C>( | |
this Func<Env, A> fun_e_a, | |
Func<A, Func<Env,B>> f_a_f_e_b, | |
Func<A,B,C> f_a_b_c) => | |
env => f_a_b_c(fun_e_a(env), f_a_f_e_b(fun_e_a(env))(env)); | |
} | |
class Id { } | |
class Customer { } | |
class Criteria | |
{ | |
public string Context { get; set; } | |
} | |
class Report | |
{ | |
public Report(CreditHistory c) | |
{ | |
} | |
} | |
class Unit { } | |
class CreditHistory { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment