Maybe.fromNullable turns a possibly null value into a Maybe so later code can map over it instead of checking for null every step. section 5.3
It is used around uncertain lookups, such as fetching records or reading nested properties, and it keeps the return type honest about absence. section 5.3
Safe lookup pipeline
A lookup can return Just(Address(...)) when data exists, or Nothing when it does not. After wrapping with Maybe.fromNullable, property access stays in the same chain, and getOrElse can supply a fallback like 'Country does not exist!' or a form default.
const findStudent = R.curry(function(db, ssn) {
return wrap(find(db, ssn)); #1
});
const getAddress = function(student) {
return wrap(student.fmap(R.prop('address'))); #2
}
Shows the wrapper style used before the Maybe-specific form, with a lookup wrapped and then mapped for address access. section 5.3
Common roles in this material include:
- wrapping uncertain database or collection results before mapping further. section 5.3
- enforcing preconditions by turning invalid inputs into Nothing. section 5.3
- supporting defaults through getOrElse when data is missing. section 5.3
Maybe.fromNullable is a beginner-friendly null guard that teaches the shape of safe function chains before more advanced error-handling types appear. section 5.3
