So You Want to be a Functional Programmer (Part 3)

Function Composition

var add10 = function(value) {
return value + 10;
};
var mult5 = function(value) {
return value * 5;
};
var add10 = value => value + 10;
var mult5 = value => value * 5;
var mult5AfterAdd10 = value => 5 * (value + 10)
var mult5AfterAdd10 = value => mult5(add10(value));
add10 value =
value + 10
mult5 value =
value * 5
mult5AfterAdd10 value =
(mult5 << add10) value
f x =
(g << h << s << r << t) x

Point-Free Notation

-- This is a function that expects 1 parametermult5AfterAdd10 value =
(mult5 << add10) value
-- This is also a function that expects 1 parametermult5AfterAdd10 =
(mult5 << add10)

Trouble in Paradise

add x y =
x + y
mult5 value =
value * 5
-- This is wrong !!!!mult5AfterAdd10 =
(mult5 << add) 10
var mult5AfterAdd10 = mult5(add(10)); // this doesn't work
var mult5AfterAdd10 = y => mult5(add(10, y)); // not point-free

My Brain!!!!

--

--

Software Engineer and Architect, Teacher, Writer, Filmmaker, Photographer, Artist…

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store