Description
For example, for binary-search
, the Zig track currently requires the user to return an error when the input is empty:
zig/exercises/practice/binary-search/test_binary_search.zig
Lines 56 to 58 in c5ece12
or the value is not found:
zig/exercises/practice/binary-search/test_binary_search.zig
Lines 44 to 46 in c5ece12
But we can consider the empty array to be a normal case of "value not found", in which case the only possibilities are "value found, or value not found". Then we can return an optional. The Zig stdlib does that - the implementation of binarySearch
returns ?usize
I'll propose changing this one. But we should look at all the exercises and think about whether it's better to return an optional, rather than an error union. Especially exercises where the error set is of length 1.
As of 2023-03-16, the exercises that can return a custom error are:
collatz-conjecture
grains
hamming
queen-attack
triangle
(considered in exercises(triangle): return an optional, not an error union #257)
We previously had:
binary-search
(removed in exercises(binary-search): return an optional, not an error union #259)rna-transcription
(removed in exercises(rna-transcription): remove untested RnaError #258)
I might propose removing more custom errors.