Functional approach specifics

Pure functions – no side effects, nothing else than transforming input parameters into returning value. State is kept outside, it can be passed into function and returned from it.

Techniques:

  • First-class citizen functions
  • High order functions
  • Anonymous functions
  • Closures
  • Currying
  • Lazy evaluation

Referential transparency – function call can be replaced by its returning value

Higher-order-function – function that accepts as an input other function

Partial function application (currying) – transform function with two parameters into function with one parameter, giving the dropped parameter a some value

Functional data structures – are immutable.

Instead of exceptions -> Option, Either, Result – returning values

Laziness – evaluating parameter when it used, but not declared

Memoization – remembering some resource-consuming operation’s result, and returning for later calls (some kind of caching)

Strict functions – all parameters are evaluated before function call, non-strict functions – with lazy parameters

Recursive functions consumes a data, corecursive – produces, both need terminating condition.

Monoid – set of some type, binary operation that takes two instances of the type and returns a new instance of the type, and empty “identity” element

Monads

  • computation context for other value
  • container, with two (or three) function defined: unit (constructor) and flatMap OR unit and compose OR unit, map, join

It is always possible to transform impure function into pure one, with two side-effects, one producing the pure function input, other consumes pure function output.

Effect – an object that contains an operation that produces side-effect, it has a method that executes a side-effect

Side-effect – is actually non-functional operation

Advertisements

About DmitryKrinitsyn
Software developer and muay thai adept

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: