logoalt Hacker News

rene_dtoday at 4:39 AM3 repliesview on HN

Optionals handle this in zig:

  var value: ?T = null;
Write:

  value = 10;
Read:

  if (value) |x| x+=1

Replies

continuationaltoday at 4:48 AM

Sure, but this is an example from the article, and pertains to sum types in general, not just Maybe.

show 2 replies
nesarkvechneptoday at 4:42 AM

Came to say this. Early in my career I really thought implementing Maybe in any language is necessary but not I know better. Use the idioms and don’t try to make every language something it’s not.