knownSize should return Option[Int] #18324
Replies: 2 comments 1 reply
-
It makes sense to define Just like we have |
Beta Was this translation helpful? Give feedback.
-
The doc could suggest the quaint Compare the huge comment on (deprecated) |
Beta Was this translation helpful? Give feedback.
-
The following code prints
-1
I was reasonably surprised by this behavior and though this may not (or maybe) qualify as a type safety issue, I walked away with the sense of lack of type safety.
Rationale/Ask: If the length cannot be produced in constant time, then do not return an incorrect value, instead, return
None
since there is nothing to be returned (the value does not exist in constant time effort). If there is some value to be returned, then return a value of typeSome[Int]
.I searched for
knownSize
and did not find anything related to it.Thank you.
Pedro
Beta Was this translation helpful? Give feedback.
All reactions