Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>I don't think it's too bad to have a failing function return a special value like `Nothing` to indicate that: `return Nothing` is no more difficult than `throw SomeException`, `exit 1`, etc.

Yes, it is a less bad alternative than many others, such as explicit error codes w/o wrapping or exceptions. (And all of these are obviously arguable...)

However, just not having to do anything is even better. And if you use a pipe/filter pattern (not just simulate it by threading functions along), then the current filter sends the result of its processing to the next filter. For example, assuming we have a filter object whose next filter is in the target instance variable:

    target writeObject: inputString upperCaseString.

If it has nothing to send, it simply doesn't send anything. Done.

    inputString isGood ifTrue: [ target writeObject: inputString upperCaseString ].

No need to return a Maybe that denotes "Maybe I have a value, maybe not". If you don't have a value, just don't send anything, and your happy path never has to deal with error cases.

Similar for multiple values. Just write multiple values to the next filter. No need to return collections and flatmap them.

         target writeObject: inputString upperCaseString.
         target writeObject: inputString lowerCaseString.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: