Skip to content

Instantly share code, notes, and snippets.

View mateuszsokola's full-sized avatar

Mateush mateuszsokola

View GitHub Profile

Currying

A curried function takes a single argument and returns another function that takes the next argument until it can evaluate to a result.

Example implementation

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
@mateuszsokola
mateuszsokola / _Higher-Order-Functions.md
Created July 28, 2017 17:56
Higher Order Functions

Higher Order Functions

Higher Order Functions (HOF) take one or more functions as arguments and they must be trigger in the first order. They often return function as the output.

When I use HOF?

  • Defining callbacks
  • Composition
  • map / reduce

Closures

Closures are scope-bounded bindings.

When can i use them?

  • hide variables
  • hide private functions
  • factories

Composition

There are two kinds of composition - object composition and function composition:

  • object composition - way of combining simple objects into complex ones.
  • function composition - way of combining simple functions to build more complicated ones.

Why composition is better than inheritance?

It doesn't encourage developers to build large object heritage, so applications aren't complex like enterprise Java apps. We limit the future predition to minimum.

@mateuszsokola
mateuszsokola / _PureFunctions.md
Last active August 9, 2021 14:36
Pure Functions

Pure functions

A pure function for given the same input will always return the same output and evaluation of this function will not cause any side effects.

Advantages of using pure functions:

  • easy to test, as they always return the same value,
  • easy to debug, as they shouldn't cause any race conditions and circular dependencies,
  • simple and independent, as they don't cause any side effects (it makes design clean),
  • easy to scale application up, as they shouldn't rely on machine state.