I just stumbled upon this edge case that was non-intuitive to me. Now I’m wondering if this behavior makes sense or not.
It has to do with String.at
when the string
is nil
and position is 0
:
String.at nil, 0
=> nil # Was expecting an error here, as in the next example:
String.at nil, 1
=> ** (FunctionClauseError) no function clause matching in String.Unicode.next_grapheme_size/1
I was surprised that nil
was returned because all (most?) String functions will raise (some sort of) a FunctionClauseError
when the input string is not a binary. Is that a wrong assumption?