Maybe
Simple Maybe Monad
Check spec for more examples
it('Does not propagate null', () => {
function getUser() {
return new Maybe({
getAvatar: function() {
return new Maybe(null); // no avatar
}
});
}
const url = getUser()
.chain(user => user.getAvatar())
.chain(avatar => avatar.url)
expect(url.isNothing()).toBe(true);
})