Skip to content

[Error] return a ? Error() : b should work #7

@arian

Description

@arian

Instead of writing

MaybeError<int32> safe_divide(int32 a, int32 b) {
  if (b == 0) return Error(); 
  else return (a / b);
}

You should be able to write

MaybeError<int32> safe_divide(int32 a, int32 b) {
  return (b == 0) ? Error() : (a / b);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions