|
|
|
|
|
by lkitching
1673 days ago
|
|
The check has to go somewhere and the caller to div has the most context in the event the divisor is 0. If you return an optional from div then you either impose the check on all the callers, or just propagate None everywhere and some top-level function has to deal with mysteriously missing values. The NonZero type should be responsible for checking the wrapped value is non-zero, you will probably want safe and unsafe constructor functions Int -> Optional[NonZero[Int]]
Int -> NonZero[Int]
where the unsafe version throws.If this is overkill for your application then I'd prefer throwing an exception in div rather than encoding the failure in the return type. |
|