Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Avoid Null Checks by Replacing Finders with Tellers. Parent comment
The example given in the article is:
data_source.person(id) do |person| person.phone_number = phone_number data_source.update_person person end
def maybe_bind(x, &blk) if !x.nil? blk.call(x) else nil end end
nil or X, (X -> nil or Y) -> nil or Y
bind :: m a -> (a -> m b) -> m b return :: a -> m a
There are no comments on this comment yet.
The example given in the article is:
You can abstract this pattern a little by putting it in a function: Now consider the type of this function: A monad is any type for which you can define bind and return. They have the Haskell types: "maybe_bind" is very similar to "bind"; just replace "m" with "nil or" and uncurry. "return" is trivial to implement.