Functions: Am I pure?

Pure functions

What are functions and FP

square function
/*
* domain: number
* co-domain: number
* square: x -> x * x
*/
function square(x: number): number {
return x * x;
}

What purity means to a function

function doubleNum(num: number): number {
return 2 * num;
}
const x = doubleNum(3); //6// should be same as
const x = 6;
// then doubleNum(num) is said to referentially transparent

Pure functions

Purity and testability

Get in touch

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store