-
-
Save simeg/22d08498123864fd789dfea64a6ab8c5 to your computer and use it in GitHub Desktop.
FP in JS 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This function is pure because it's determinisic. | |
// It has no side effects. | |
// Nothing outside the function can influence the output. | |
// addTen(5) will _always_ be 15 | |
const addTen = input => { | |
return input + 10; | |
}; | |
// Fetch the number from the database | |
const numberFromDb = DB.getNumber(); | |
// This function is not pure because it's not deterministic. | |
// It has a side effect (the numberFromDb value). | |
// We cannot know for sure that the outcome will be the same | |
// every time we call it, and that's why it's not pure | |
const addWithNumberFromDb = input => { | |
return input + numberFromDb; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment