int diff = 2; Functional.filter2_fn<int, int> f = delegate(int a, int b) { return Math.Abs(a - b) > diff; }; diff = 3; bool retval = Functional.forAll2(f, l, m);
because, by the time we come to use
f, the value stored in
diffhas changed to 3.
int diff = 2; Functional.filter2_fn<int, int> f = delegate(int a, int b) { return Math.Abs(a - b) > diff; }; diff = 3; bool retval = Functional.forAll2(f, l, m);
f, the value stored in
diffhas changed to 3.
public static filter_fn<A> not<A>(filter_fn<A> f) { return delegate(A a) { return !f(a); }; } public static bool forAll<A>(filter_fn<A> f, IEnumerable<A> input) { return !exists(not(f), input); }
public void CompositionTest1() { int[] i = { 1, 2, 3, 45, 56, 6 }; bool allOdd = Functional.forAll(Functional.dIsOdd, i); bool notAllOdd = Functional.exists(Functional.not(Functional.dIsOdd), i); Assert.IsFalse(allOdd); Assert.IsTrue(notAllOdd); }
List<ReportItem2> value = new List<ReportItem2>(); IEnumerable<MComponentDetails> components = SwapUtils.GetBasketComponents(swap); foreach (MComponentDetails detail in components) { string sedol = InstrumentUtils.GetSedol(detail.fSicovam); string instrName = InstrumentUtils.GetInstrName(detail.fSicovam); value.Add(new ReportItem2(sedol, instrName, columnConfig)); }
List<ReportItem2> value = new List<ReportItem2>(); IEnumerable<MComponentDetails> components = SwapUtils.GetBasketComponents(swap); value.AddRange(Functional.map(sec(columnConfig), components));
secand enable it to take a parameter (instead of simply being a delegate) is far too much; the second is that, unbelievably, the compiler will not implicitly cast from
IEnumerable<MComponentDetails>to
IEnumerable<object>Unbelievable!
private class sec { private static ExportColumnConfiguration _config; public static Functional.fnf(ExportColumnConfiguration config) { _config = config; return sec_func; } private static Functional.fn sec_func = CreateReportItem2FromSecurity; private static ReportItem2 CreateReportItem2FromSecurity(MComponentDetails detail) { string sedol = InstrumentUtils.GetSedol(detail.fSicovam); string instrName = InstrumentUtils.GetInstrName(detail.fSicovam); return new ReportItem2(sedol, instrName, _config); } }