Skip to content

Instantly share code, notes, and snippets.

@isthatcentered
Last active January 7, 2021 03:25
Show Gist options
  • Save isthatcentered/658751d026bced4a262fbd1e534e09a5 to your computer and use it in GitHub Desktop.
Save isthatcentered/658751d026bced4a262fbd1e534e09a5 to your computer and use it in GitHub Desktop.
Functional Programming cheat sheet

Partial vs Total

  • domain/codomain
  • deterministic

Referential transparency

def blah1() = if(false) throw new Exception else 2 

def blah2() = {
  val a = throw new Exception
  if(false) a else 2
}

// blah1(): 2 
// blah2(): java.lang.Exception at ...

Laws

Identity

a + identity == a # Left identity
identity + a == a # Right identity

Commutative

a + b == b + a

Associative

a + ( b + c ) == (a + b ) + c  

Idempotent

a + a == a

Typeclasses

Semigroup

Monoid

Functor

Applicative

Monad

Category Theory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment