A tuple is a sequence of values. The values can be any type, a
nd they are indexed by integer, so tuples are not like lists. The most important difference is that tuples are immutable. Tuples are used whenever you want to return multiple results from a function.
It is good practice to enclose tuples in parentheses
t = (‘p’, ‘q’, ‘r’, ‘s’, ‘t’)
Tuple is not yet available in C#, however it shouldn’t be hard to create your own version.
Functional programming differs from the usual imperative and object oriented style in many ways, so I’d like to talk about the basic concepts that are essential for functional programming. Functional programming is a paradigm which concentrates on computing results rather than on performing actions.
Let me give a quick example, I want to build a program that would support the following operations.
- It has to sum the numbers between the given range.
- It has to multiply the numbers between the given range.
In essence, a closure is a block of code which can be executed at a later time, but which maintains the environment in which it was first created – i.e. it can still use the local variables etc of the method which created it, even after that method has finished executing.
Currying a method call breaks the single method into a chain of methods. Suppose that we have a simple function that takes two arguments and returns a value.