Closed oscbyspro closed 1 month ago
I'll make BinaryInteger/factorial()
return Optional<Fallible<Self>>
and add a similar Fallible<T>
method.
Note that the optional part doesn't affect the assembly as long as you unsafelyUnwrapped
and that many binary integer algorithms are such that some types can unsafelyUnwrapped
unconditionally. Alternatively, you can use the Guarantee
approach when you have more information than the compiler.
BinaryInteger.leniently(Swift.BinaryFloatingPoint)
is an excellent use case forOptional<Fallible<T>>
. Thenil
anderror
both have distinct and sensible interpretations and the optional part doesn't even increase the size of the return type's memory layout.I have previously hoisted some
Fallible<T>
return types by mapping errors toOptional<T>
. I think it's worth consideringOptional<Fallible<T>>
as an alternative because it is more powerful. Tangentially, I could perhaps do something similar with infinite-by-finite division (#69).