Christian Maeder wrote:
Donald Bruce Stewart schrieb:
Question over whether it should be:
    splitBy (=='a') "aabbaca" == ["","","bb","c",""]
  or
    splitBy (=='a') "aabbaca" == ["bb","c"]

I argue the second form is what people usually want.

Yes, the second form is needed for "words", but the first form is
needed for "lines", where one final empty element needs to be removed
from your version!

Prelude> lines "a\nb\n"
["a","b"]
Prelude> lines "a\n\nb\n\n"
["a","","b",""]

Prelude.lines and Prelude.unlines treat '\n' as a terminator instead of a separator. I'd argue that this is poor design, since information is lost ie lines . unlines === id whereas unlines . lines =/= id whereas if '\n' had been properly conceived of as a separator, the identity would hold.

So I vote for the first option ie:

   splitBy (=='a') "aabbaca" == ["","","bb","c",""]


Regards, Brian.
--
Logic empowers us and Love gives us purpose.
Yet still phantoms restless for eras long past,
congealed in the present in unthought forms,
strive mightily unseen to destroy us.

http://www.metamilk.com
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to