Skip to content

Instantly share code, notes, and snippets.

@mateuszsokola
Created July 30, 2017 15:54
Show Gist options
  • Save mateuszsokola/40189b07a232113b462bfd9143fce299 to your computer and use it in GitHub Desktop.
Save mateuszsokola/40189b07a232113b462bfd9143fce299 to your computer and use it in GitHub Desktop.
Functors

Functors

According to wikipedia a functor is a type of mapping between categories arising in category theory. To simplefy it, functors are objects, types, function that contain implementation of the map function. The map transforms contents of the functor.

What needs to be fulfilled?

  • implementation of map function that transforms contents of the functor
  • map always returns functors of the same type

Examples

  • arrays
const itemsOnCheck = [
{
name: 'fries',
price: 599,
taxPercent: 0.1
}, {
name: 'burger',
price: 1599,
taxPercent: 0.1
}, {
name: 'coca-cola',
price: 599,
taxPercent: 0.2
}
]
// #map transformed contents of the array.
itemsOnCheck.map(item => item.price); // [ 599, 1599, 599 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment