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

A few things that need responding to. First, optional is the same as a maybe. They're different names for the same thing.

If you want to return a status instead of nothing, you use an Either type (as mentioned in the post). In an Either, you populate left or right, but not both. You can let left be your status and right be your template type. You could codify this as StatusOr<T>.

In a StatusOr land, you return if there's an error; otherwise you continue the computation. This gives a few advantages, but one is that you control the flow of control. (This is also done decently with exceptions in Java, iirc)

However, all of these - maybes, either - they make your functions composable.

There's a good talk... Railroad oriented programming... that dives into this.



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

Search: