Answer the question
In order to leave comments, you need to log in
Is functional programming possible in C# without LINQ?
Something more like functional programming in php, js.
Answer the question
In order to leave comments, you need to log in
Quite possible. See:
static IEnumerable<TResult> Map<TIn, TResult>(this IEnumerable<TIn> seq, Func<TIn, TResult> mapper){
foreach(TIn item in seq) yield return mapper(item);
}
enum Parity { Even, Odd }
static void Test(){
List<int> numbers = new List<int> { 1, 2, 3, 4, 5, 6 };
Func<int, Parity> parity = (num) => num % 2 == 0 ? Parity.Even : Parity.Odd ;
foreach(var parity in numbers.Map(parity))
Console.Write(parity.ToString() + ", ");
}
"Odd, Even, Odd, Even, Odd, Even, ".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question