Skip to content

Instantly share code, notes, and snippets.

@kdipaolo
Created January 28, 2019 16:41
Show Gist options
  • Save kdipaolo/09b6239670fb30c30f295595b60e142f to your computer and use it in GitHub Desktop.
Save kdipaolo/09b6239670fb30c30f295595b60e142f to your computer and use it in GitHub Desktop.
functional_programming

first class functions

Functions can be used just like any other value: they can be passed around, assigned to variables, or they can be stored in arrays or objects.


const introduction = () => "Hello! My name is "
const welcome = (name, intro) => intro() + name
welcome("Kurt", introduction()) // Hello! My name is Kurt

Higher order functions

  • Take other functions as arguments, return other functions
  • Common example: Array.map function, take a function and applies it to every element in an array:
const numbers = [1,2,3,4,5]
const transformNums = x => x + 2
numbers.map(transformNums) // [3,4,5,6,7]

another example:

const makeGreeter = greeting => name => `${greeting}, $[name}`;
const greet = makeGreeter('Hello')
greet('Kurt') // Hello, Kurt

application state

  • current values of all the variables, objects, network sockets, etc.
  • It is basically all of the information that represents what is currently happening in the application.
  • pure functions can’t access or mutate shared state.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment