Here is how it can be done in C#:
int[] fullList = { 4, 31, 24, 2, 1, 13, 56 };
int[] evens = Array.FindAll(fullList, x => (x % 2 == 0));
Array.ForEach<int>(evens, x => Console.WriteLine(x.ToString()));
Now in F#
let fullList = [4; 31; 24; 2; 1; 13; 56]
let evens = fullList > List.filter (fun x -> (x % 2 = 0) ) > List.to_array
do Array.ForEach(evens, (fun x -> printfn "%d" x))
Pretty similar as you can see. Now lets see it in Ruby:
fullList = [ 4, 31, 24, 2, 1, 13, 56]
evens = fullList.select { x (x % 2 == 0)}
puts evens
Nice and simple. For comparison's sake, let's look at the non functional way of doing this in C# (I will use C# 2.0 here to make it at least a little easier):
int[] fullList = { 4, 31, 24, 2, 1, 13, 56 };
List<int> evens = new List<int>();
foreach (int num in fullList)
{
if (num % 2 == 0)
evens.Add(num);
}
foreach (int n in evens)
Console.WriteLine(n);
Functional programming offers great benefits when it comes to simplifying code and you aren't too limited to in your choice of languages to do it in. Granted there will be bigger differences when using more complicated examples but its nice to see how available it has become.
Best Big Data Hadoop Training in Hyderabad @ Kalyan Orienit
ReplyDeleteFollow the below links to know more knowledge on Hadoop
WebSites:
================
http://www.kalyanhadooptraining.com/
http://www.hyderabadhadooptraining.com/
http://www.bigdatatraininghyderabad.com/
Videos:
===============
https://www.youtube.com/watch?v=-_fTzrgzVQc
https://www.youtube.com/watch?v=Df2Odze87dE
https://www.youtube.com/watch?v=AOfX-tNkYyo
https://www.youtube.com/watch?v=Cyo3y0vlZ3c
https://www.youtube.com/watch?v=jOLSXx6koO4
https://www.youtube.com/watch?v=09mpbNBAmCo