Published
Edited
Jan 10, 2020
1 star
Insert cell
Insert cell
// Increment a number
incr = n => n + 1
Insert cell
Insert cell
incr(0)
Insert cell
incr(incr(0))
Insert cell
incr(incr(incr(0)))
Insert cell
Insert cell
(parm1, parm2) => parm2 + parm1
Insert cell
Insert cell
parm2 => parm2 + 1
Insert cell
Insert cell
parm1 => parm2 => parm2 + parm1
Insert cell
Insert cell
adder = val1 => val2 => val2 + val1
Insert cell
Insert cell
increment = adder(1)
Insert cell
increment(0)
Insert cell
Insert cell
ZERO = transform => start_value => start_value
Insert cell
ONE = transform => start_value => transform(start_value)
Insert cell
TWO = transform => start_value => transform(transform(start_value))
Insert cell
Insert cell
ZERO(increment)(0)
Insert cell
ONE(increment)(0)
Insert cell
TWO(increment)(0)
Insert cell
Insert cell
// Increment 5 using the function TWO
TWO(increment)(5)
Insert cell
Insert cell
decrement = adder(-1)
Insert cell
TWO(decrement)(5)
Insert cell
Insert cell
// Increment the character 'A' using the function TWO
TWO(increment)('A')
Insert cell
Insert cell
// Concatenate a character to the end of a string
// This function needs to remember the character being concatenated,
// so we wrap the concat() function call within a partial function
// that can remember the value of "char".
//
// "acc" is the accumulator into which the characters are
// concatenated
str_concatenate = char => acc => acc.concat(char)
Insert cell
Insert cell
ZERO(str_concatenate('+'))('')
Insert cell
ONE(str_concatenate('+'))('')
Insert cell
TWO(str_concatenate('+'))('')
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more