Wednesday, May 13, 2015

Maybe, Just, and None in Objective-C

Graham Lee:

OK, if everything succeeds you can use the Maybe result (which will be Just the value) as if it is the value itself.

[…]

The other case is that your operation failed, so we need to represent that. We need to know what type of object you don’t have(!), which will be useful because we can then treat the lack of value as if it is an instance of the value. How will this work? In None, the no-value version of a Maybe, we’ll just absorb every message you send.

[…]

The NSError-star-star convention lets you compose possibly-failing messages and find out either that it succeeded, or where it went wrong. But it doesn’t encapsulate what would have happened had it gone right, so you can’t just rewind time to where things failed and try again. It is possible to do so, simply by encapsulating the idea that something might work…maybe.

Comments RSS · Twitter

Leave a Comment