Bifunctor (Either, Pair, Task) - class allows us to deal with two inner types (left and right!).
const { Left, Right } = require('fantasy-eithers')
Function.prototype.map = function (f) {
return x => f(this(x))
}
//- Where everything changes...
const login = user =>
user.name == 'Tom'
? Right(user)
: Left('Boo')
//- Function map === "piping".
//+ failureStream :: String
//+ -> HTML
const failureStream =
(x => x.toUpperCase())
.map(x => x + '!')
.map(x => '<em>' + x + '</em>')
//+ successStream :: User
//+ -> HTML
const successStream =
(x => x.name)
.map(x => 'Hey, ' + x + '!')
.map(x => '<h1>' + x + '</h1>')
const user = { name: 'Tom' }
console.log(
//- We can now pass in our two
//- possible application flows
//- using `bimap`!
login(user).bimap(
failureStream,
successStream)
)
?
?
Profunctor - ?