4. Pure function
Given the same input, will always return the same output
Doesn’t have any side effects
1
2
5. Pure function
// pure
Math.Max(5, 8)
"Typescript".Length
"Typescript".ToUpper()
var numbers = new List<int> { 0, 8, 9, 1 };
numbers.OrderBy(x => x)
numbers.Where(x => x % 2 == 0)
// impure
var numbers = new List<int> { 0, 8, 9, 1 };
numbers.Sort();
Action<String> greeting = name =>
{
Console.WriteLine("hi" + name + " !");
}
6. Benefits of pure functions
Easier to reason about
1
2
3
4
5
6
7
Easier to combine
Offer Referential Transparency
Easier to parallelize
Are Memoizable
Can be lazy
Easier to test
16. Algebraic Data Type(ADT)
Algebra consists of:
A set of objects
The operations that can be applied to those objects to create new objects
1
2
Examples
Numeric Algebra
Relational Algebra
22. Pattern Matching
A pattern match combines an applicability test and destructuring bind
Destructuring bind extract values from an object
Applicability test determines if the pattern matches the target
1
2