by ppcsf · 10y ago · 0 comments
Optional<WidgetFriend> GetWidgetFriend(Widget widget)
and WidgetFriend had an Optional<FriendName> property, we could simply write [1] from widget in _widgetRepository.FindById(widgetId)
from friend in _widgetRepository.GetWidgetFriend(widget)
from name in friend.Name
select name;
and get an Optional<FriendName>, without having to repeat all the tedious pattern matching of Some or None for every call. If any of those calls returns a None, the entire evaluation short-circuits and we get a None result at the end.Of course, we can still write
Optional<Widget> widget = null;
which is the problem with not fixing this issue on a language level.[1] You'd have to implement Select and SelectMany, instead of Map and Bind, to get query syntax like this.