Found against: gren 0.6.6, gren-lang/core 7.4.2, node 22
Summary
String.words's docs say this:
Break a string into words, splitting on chunks of whitespace.
When the string it parses has 2 words, the resulting Array has 2 items.
When the string has 1 word, it returns an Array of 1 item, regardless of whitespace before or after.
Array.length (String.words "a b") -- 2
Array.length (String.words " a ") -- 1, the padding dropped
However when the input has no words, the result is not an empty Array.
Instead it is an Array of one empty string.
Array.length (String.words "") -- 1
Array.first (String.words "") -- Just ""
The reason I believe this is a defect rather than a choice is that words never returns
empty strings anywhere else. " a " does not answer [ "", "a", "" ]; a run of
whitespace between two words does not return empty strings between them.
Every caller can therefore assume that a word is a non-empty string.
Looking at it another way, it's odd that the length of words "a" is the same length of words ""
> String.words "a b c"
["a", "b", "c"] : Array String
> String.words "a b"
["a", "b"] : Array String
> String.words "a"
["a"] : Array String
> String.words ""
[""] : Array String
Found against:
gren0.6.6,gren-lang/core7.4.2, node 22Summary
String.words's docs say this:When the string it parses has 2 words, the resulting Array has 2 items.
When the string has 1 word, it returns an Array of 1 item, regardless of whitespace before or after.
However when the input has no words, the result is not an empty Array.
Instead it is an Array of one empty string.
The reason I believe this is a defect rather than a choice is that
wordsnever returnsempty strings anywhere else.
" a "does not answer[ "", "a", "" ]; a run ofwhitespace between two words does not return empty strings between them.
Every caller can therefore assume that a word is a non-empty string.
Looking at it another way, it's odd that the length of
words "a"is the same length ofwords ""