Functional & Reactive Programming

Abhinav Rastogi

  What is reactive programming

  programming with async data streams

principles

  Responsive

  Smooth, should not hang, main thread unblocked

  Resilient

  Remain responsive under stress or things going down

  Scalable

  Easily-upgradeable in parts

Scaling Up

  maximize resources of single machine

Scaling Out

  distribute across cluster of cheap hardware

  Message-driven

  Event-based

  based on events which are monitored by zero or more observers

Actor-based

  based on message-passing, directed to a recipient

  What is functional programming

  Composition, pipelining,

higher-order-functions

  Immutable data, first class functions,

tail call optimisation

  These are language features!

  mapping, reducing, pipelining,

recursing, currying

These are programming techniques!

  parallelisation, lazy evaluation, determinism

These are advantages of FP!

Simple definitions:

Absence of side effects

  Don’t rely on data outside the function.

  Write declaratively, not imperatively

var arr = [1,2,3]

// non-functional

var i;
for(i=0; i<arr.length; i++) {
    arr[i] = arr[i] + 1;
}

// functional

map(arr, function(item) {
    return item += 1;
})

map

reduce

filter

zip

mergeAll

Functional and Reactive Programming

By Abhinav Rastogi

Functional and Reactive Programming

  • 792