3 ms·
When it's occasionally useful return (type, err), but generally the two results are distinct so there's no need to return two results in the general case when o
by __s 5y ago
When it's occasionally useful return (type, err), but generally the two results are distinct so there's no need to return two results in the general case when one suffices
Indeed, I recently updated some code to return a relevant value in the error case: https://github.com/wal-g/wal-g/pull/1143/files#diff-d896e5d50cc3693c055fd9a6cfbfaccd1cc82fc3aaea3881c38cf9eb15a63b50R240 https://github.com/wal-g/wal-g/pull/1143/files#diff-d896e5d5...
where true means the error is rooted in a corrupted page, & false means that the error isn't due to a corrupted page. It does feel a little dirty & a comment is probably necessary to make this case clear
Still, Result can work here. For example, Rust's binary_search https://doc.rust-lang.org/std/vec/struct.Vec.html#method.binary_search https://doc.rust-lang.org/std/vec/struct.Vec.html#method.bin...
which returns Ok(idx) when that's the location of the element, or Err(idx) when that's the location the element would be if it were there (this can be a bit annoying when you just want to insert, since you end up writing `let idx = match result { Ok(idx) => idx, Err(idx) => idx }`)