SlideShare a Scribd company logo
Everything is
composable
Hello!I am Victor Igor
You can find me at @victorvoid
1.
Programming paradigms
A “new” perspective on modeling the flow of your software.
“
In practice, each paradigm comes with its
own way of thinking and there are
problems for which it is the best approach.
Programming paradigms
◍ Functional programming
◍ Object-oriented programming
◍ Logic programming
◍ Symbolic programming
Composability
The essence of software development is composition.
Composability
const dotChainy = str =>
str
.toLowerCase()
.split(' ')
.map(c => c.trim())
.reverse()
.filter(x => x.length > 3)
.join('')
Composability
const doin_Thangs = str =>
_.chain(str)
.words()
.groupBy(s => s.length)
.orderBy(x => x.length)
.take(2)
.flatten()
.value()
Composability
const reactiveUpInHere = el =>
fromEvent(el, 'keyup')
.map(e => e.target.value)
.filter(text => text.length > 2)
.throttle(500)
.distinctUntilChanged()
Composability
(->> (range 1000000000000000000)
(filter even?)
(map inc)
(take 5)
(partition 2 1))
;;=> ((1 3) (3 5) (5 7) (7 9))
Composability
player
.unitWithinRange(2)
.where(UnitIs.Enemy)
.where(UnitIs.Tank)
.DoDamage(5)
Composability
const dotChainy = str =>
str
.toLowerCase()
.split(' ')
.map(c => c.trim())
.reverse()
.filter(x => x.length > 3)
.join('')
Composability
const dotChainy = str =>
str
.toLowerCase()
.split(' ')
.map(c => c.trim())
.reverse()
.filter(x => x.length > 3)
.join('')
‘Victor and Igor’
Composability
const dotChainy = str =>
str
.toLowerCase()
.split(' ')
.map(c => c.trim())
.reverse()
.filter(x => x.length > 3)
.join('')
‘victor and igor’
Composability
const dotChainy = str =>
str
.toLowerCase()
.split(' ')
.map(c => c.trim())
.reverse()
.filter(x => x.length > 3)
.join('')
[‘victor’,‘and’,‘igor’]
Composability
const dotChainy = str =>
str
.toLowerCase()
.split(' ')
.map(c => c.trim())
.reverse()
.filter(x => x.length > 3)
.join('')
[‘victor’,‘and’,‘igor’]
Composability
const dotChainy = str =>
str
.toLowerCase()
.split(' ')
.map(c => c.trim())
.reverse()
.filter(x => x.length > 3)
.join('')
[‘igor’,‘and’,‘victor’]
Composability
const dotChainy = str =>
str
.toLowerCase()
.split(' ')
.map(c => c.trim())
.reverse()
.filter(x => x.length > 3)
.join('')
[‘igor’,‘victor’]
Composability
const dotChainy = str =>
str
.toLowerCase()
.split(' ')
.map(c => c.trim())
.reverse()
.filter(x => x.length > 3)
.join('')
‘igorvictor’
Composability
const doThing = str => {
const lower = str.toLowerCase()
const words = lower.split(' ')
words.reverse()
for(let i in words) {
words[i] = words[i].trim()
}
let keepers = []
for(let i in words) {
if(words[i].length > 3) {
keepers.push(words[i])
}
}
return keepers.join('')
}
Composability
const doThing = str => {
const lower = str.toLowerCase()
const words = lower.split(' ')
words.reverse()
for(let i in words) {
words[i] = words[i].trim()
}
let keepers = []
for(let i in words) {
if(words[i].length > 3) {
keepers.push(words[i])
}
}
return keepers.join('')
}
Composability
const dotChainy = str =>
str
.toLowerCase()
.split(' ')
.map(c => c.trim())
.reverse()
.filter(x => x.length > 3)
.join('')
Composability
Composability
“The major contributor to this complexity
in many systems is the handling of state
and the burden that this adds when trying
to analyse and reason about the system.”
Ben Moseley & Peter Marks
Out of the Pit 2006
Control flow
Composability
Composability
Code volume
Composability
Composability
Composability
Composability
const dotChainy = str =>
str
.toLowerCase()
.split(' ')
.map(c => c.trim())
.reverse()
.filter(x => x.length > 3)
.join('')
Everything is composable
Everything is composable
Programming !== Math
Programming !== Math
Programming !== Math
try {
return f(x)
} catch(e) {
console.error(e)
}
Programming !== Math
if {
return f()
} else(e) {
return y
}
Programming !== Math
let stuff = [1, 2, 3]
stuff = [1, 2]
Programming !== Math
let stuff.splice(0, 2)
stuff.pop()
Programming !== Math
for(let thing in things) {
if(thing.amount > 100) keepers.push(thing.name)
}
for (i = 0; i < cars.length; i++) {
text += cars[i] + "<br>";
}
while (i < 10) {
text += "The number is " + i;
i++;
}
Assignment
Callbacks
Loops
Side Effects
Branching
Errors
Programming !== Math
Programming !== Math
Programming != Math
Programming !== Math
f.g
Programming !== Math
f.g = x => f(g(x))
Programming !== Math
str.toUpperCase().trim()
Programming !== Math
trim(toUpperCase(str))
Category theory
Category Theory
What’s category theory?
What’s category theory?
Category Theory
Categories represent abstraction of other mathematical concepts.
The paradigm shift provoked by Einstein's
theory of relativity has brought the
realization that there is no single
perspective to see the world.
Category
Category Theory
objects
Category
Category Theory
objects
Arrows or morphisms
Category
Category Theory
objects
Arrows or morphisms
Domain
dom(f) f
Category
Category Theory
objects
Arrows or morphisms
Domain/codomain
dom(f) f
cod(f)
Category
Category Theory
objects
Arrows or morphisms
Domain/codomain
dom(f)
g
cod(f)
Category
Category Theory
objects
Arrows or morphisms
Domain/codomain
f
Composition
h
Category
Category Theory
objects
Arrows or morphisms
Domain/codomain
f
Composition
h
h . f
Category
Category Theory
objects
Arrows or morphisms
Domain/codomain
Composition
Identity
World Wide Web
Category Theory
World Wide Web
Category Theory
objects = webpages
Arrows = hyperlinks
World Wide Web
Category Theory
objects = webpages
Arrows = hyperlinks
Composition = Links don’t compose
Identity
World Wide Web
Category Theory
objects = nodes
Arrows = edges
Composition = Edges don’t compose
Identity
Graphs
Category Theory
objects = sets (or types)
Arrows = functions
Composition = function composition
Identity = identity function
Programming
Functors
Category Theory
Category Theory
Functors map between categories
Functors
Category Theory
A B
Category Category
Functor
F
Category Theory
Composition Law
F(g ∘ f) = F(g) ∘ F(f)
Identity Law
F(idA) = idF(A)
Functors laws
Category Theory
“Hey, I know what can be mapped
over. An array can be mapped
over — you can map a function over an
array!”
Category Theory
Identity
const f = [1,2,3]
f.map(x => x) //[1,2,3]
Category Theory
Composition
[1,2,3].map(x => f(g(x)))
=
[1,2,3].map(g).map(f)
Composability
const nextCharForNumberString = str => {
const trimmed = str.trim()
const number = parseInt(trimmed)
const nextNumber = number + 1
return String.fromCharCode(nextNumber)
}
nextCharForNumberString(' 70 ')
//'G'
Composability
const nextCharForNumberString = str =>
return [str.trim()]
.map(trimmed => new Number(trimmed))
.map(number => number + 1)
.map(n => String.fromCharCode(n))
nextCharForNumberString(' 70')
//['G']
Category Theory
Build your own Functor
Composability
const Box = x => ({
map: f => Box(f(x))
})
const Box = x => ({
map: f => Box(f(x))
})
const nextCharForNumberString = str =>
return Box(str.trim())
.map(trimmed => new Number(trimmed))
.map(number => number + 1)
.map(n => String.fromCharCode(n))
nextCharForNumberString(' 70') //Box('G')
const Box = x => ({
map: f => Box(f(x)),
fold: f => f(x)
})
const nextCharForNumberString = str =>
return Box(str.trim())
.map(trimmed => new Number(trimmed))
.map(number => number + 1)
.fold(n => String.fromCharCode(n))
nextCharForNumberString(' 70') //'G'
Assignment
Callbacks
Loops
Side Effects
Branching
Errors
Loops
filter
map
reduce
Assignment
Callbacks
Loops
Side Effects
Branching
Errors
Callbacks
Side effects
Promise(5).then(five => five + 2)
//Promise(7)
Promise(5).then(five => Promise(five + 2))
//Promise(7)
Promise(5).map(five => five + 2))
//Promise(7)
const doThing = () =>
fs.readFile('file.json', 'utf-8', (err, data) => {
if(err) throw err
const newdata = data.replace(/8/g, '6')
fs.writeFile('file2.json', newdata, (err, _) => {
if(err) throw err
console.log('success!')
}
}
const readFile = futurize(fs.readFile)
const writeFile = futurize(fs.writefile)
const doThing = () =>
readFile('file.json')
.map(data => data.replace('/8/g', '6')
.chain(replaced =>
writeFile('file2.json', replaced))
const readFile = futurize(fs.readFile)
const writeFile = futurize(fs.writefile)
const doThing = () =>
readFile('file.json')
.map(data => data.replace('/8/g', '6')
.chain(replaced =>
writeFile('file2.json', replaced))
doThing().fork(e => console.log(e),
r => console.log('success'))
const lib = username =>
getTweets(username)
.map(tweets => truncateTo130(tweets))
.chain(tweets => writeFile('tweets.json', tweets))
lib('@victorvoid')
.chain(f => saveToS3(f))
.fork(e => console.error(e),
r => console.log(r))
Assignment
Callbacks
Loops
Side Effects
Branching
Errors
Errors
Branching
Either
data Either a b = Left a | Right b
Left('no loaded').fold(() => 'uow, error!',
s => s.toUpperCase())
//'uow, error!'
Right('loaded').fold(() => 'uow, error!',
s => s.toUpperCase())
//'LOADED'
LeftOrRight('no loaded')
.fold(() => 'uow, error!',
s => s.toUpperCase())
Right(2)
.map(x => x + 4)
.map(x => x / 2)
.fold(() => 'uow, error!',
r => r + 1)
//4
Left('ignored')
.map(x => x + 4)
.map(x => x / 2)
.fold(() => 'uow, error!',
r => r + 1)
//'uow, error!'
const getConfig = () => {
try {
return fs.readFileSync('config.json')
} catch (e) {
return null
}
}
const getPort = () => {
const str = getConfig()
if(str) {
const parsed = JSON.parse(str)
return parsed.port
} else (e) {
return 3000
}
}
const getConfig = () =>
Either.try(fs.readFileSync)('config.json')
const getPort = () =>
getConfig()
.map(JSON.parse)
.fold(e => 3000, c => c.port)
const getThing = user => {
const address = user.address
if(address){
const zip = address.match(/(d{5})$/i)
if(zip){
const city = cityByZip(zip)
if(city){
return city
} else {
return 'cant find city'
}
}
}
return 'cant find city'
}
const getThing = user =>
fromNullable(user.address)
.chain(a => fromNullable(a.match(/(d{5})$/i)))
.chain(zip => fromNullable(cityByZip(zip)))
.fold(() => 'cant find city', city => city)
Assignment
Callbacks
Loops
Side Effects
Branching
Errors
Everything is composable
React example
Component :: a -> JSX
a JSX bf g
a JSX bf g
a JSX
fb
g
const Comp = g => ({
fold: g,
contramap: f =>
Comp(x => g(f(x)))
})
const Comp = g => ({
fold: g,
contramap: f =>
Comp(x => g(f))
})
const heading = str =>
<h1>You are viewing {str}</h1>
const Title = Comp(heading).contramap(s => s.pageName)
const Comp = g => ({
fold: g,
contramap: f =>
Comp(x => g(f))
})
const heading = str =>
<h1>You are viewing {str}</h1>
const Title = Comp(heading).contramap(s => s.pageName)
Title.fold({ pageName: 'Home',
currUser: {id: '123', name: 'Victor'}})
//<h1>You are viewing Home</h1>
Learn a new language
Fantasy Land Specification
Everything is composable
References
- Mostly-adequate-guide
- Professor-frisby-introduces-composable-functional-javascript
- Ramda-fantasy
- Functors, Applicatives, And Monads In Pictures
- Bartosz Milewski - Category Theory for programmers
Thanks!Any questions?
You can find me at @victorvoid & victorvoid.me

More Related Content

PDF
Python dictionary : past, present, future
PPT
PDBC
PDF
The Curious Clojurist - Neal Ford (Thoughtworks)
PDF
Functional JS for everyone - 4Developers
PDF
Day 1c access, select ordering copy.pptx
PDF
Using Scala Slick at FortyTwo
PDF
Clojure functions midje
PDF
Python 2.5 reference card (2009)
Python dictionary : past, present, future
PDBC
The Curious Clojurist - Neal Ford (Thoughtworks)
Functional JS for everyone - 4Developers
Day 1c access, select ordering copy.pptx
Using Scala Slick at FortyTwo
Clojure functions midje
Python 2.5 reference card (2009)

What's hot (18)

PPT
Oop lecture9 13
PDF
Day 1d R structures & objects: matrices and data frames.pptx
PDF
Day 1b R structures objects.pptx
PDF
Json and SQL DB serialization Introduction with Play! and Slick
PPTX
Groovy Api Tutorial
PDF
Python lecture 05
PDF
Groovy collection api
PDF
Basic R Data Manipulation
PDF
Java script objects 1
 
ODP
Promise
PDF
JavaScript Fundamentals with Angular and Lodash
PDF
Day 2 repeats.pptx
PPTX
Python lec5
PDF
Pymongo for the Clueless
PPTX
Python 내장 함수
PDF
The java language cheat sheet
PDF
The MongoDB Driver for F#
PDF
Bai giaigk
Oop lecture9 13
Day 1d R structures & objects: matrices and data frames.pptx
Day 1b R structures objects.pptx
Json and SQL DB serialization Introduction with Play! and Slick
Groovy Api Tutorial
Python lecture 05
Groovy collection api
Basic R Data Manipulation
Java script objects 1
 
Promise
JavaScript Fundamentals with Angular and Lodash
Day 2 repeats.pptx
Python lec5
Pymongo for the Clueless
Python 내장 함수
The java language cheat sheet
The MongoDB Driver for F#
Bai giaigk
Ad

Similar to Everything is composable (20)

PPTX
Oh Composable World!
PDF
Pune Clojure Course Outline
PDF
Practical cats
PDF
Refactoring to Macros with Clojure
PDF
[FT-7][snowmantw] How to make a new functional language and make the world be...
PDF
Monads and Monoids by Oleksiy Dyagilev
ODP
Functions In Scala
PPTX
A quick introduction to R
PPTX
Introduction to python programming 1
ODP
Pick up the low-hanging concurrency fruit
PDF
mobl - model-driven engineering lecture
PDF
Ti1220 Lecture 7: Polymorphism
PPTX
R language introduction
PDF
(first '(Clojure.))
PPTX
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
PDF
Type safe embedded domain-specific languages
PDF
mobl presentation @ IHomer
PDF
A Program for Multiple Sequence Alignment by Star Alignment
DOCX
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
PDF
Node.js in 2020 - part 2
Oh Composable World!
Pune Clojure Course Outline
Practical cats
Refactoring to Macros with Clojure
[FT-7][snowmantw] How to make a new functional language and make the world be...
Monads and Monoids by Oleksiy Dyagilev
Functions In Scala
A quick introduction to R
Introduction to python programming 1
Pick up the low-hanging concurrency fruit
mobl - model-driven engineering lecture
Ti1220 Lecture 7: Polymorphism
R language introduction
(first '(Clojure.))
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Type safe embedded domain-specific languages
mobl presentation @ IHomer
A Program for Multiple Sequence Alignment by Star Alignment
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
Node.js in 2020 - part 2
Ad

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
Machine Learning_overview_presentation.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
Tartificialntelligence_presentation.pptx
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Mushroom cultivation and it's methods.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
TLE Review Electricity (Electricity).pptx
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Machine Learning_overview_presentation.pptx
NewMind AI Weekly Chronicles - August'25-Week II
Tartificialntelligence_presentation.pptx
cloud_computing_Infrastucture_as_cloud_p
Mobile App Security Testing_ A Comprehensive Guide.pdf
Mushroom cultivation and it's methods.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Univ-Connecticut-ChatGPT-Presentaion.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
TLE Review Electricity (Electricity).pptx
A comparative analysis of optical character recognition models for extracting...
Network Security Unit 5.pdf for BCA BBA.
Assigned Numbers - 2025 - Bluetooth® Document
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Building Integrated photovoltaic BIPV_UPV.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf

Everything is composable