I'm new to Clojure. The behaviour of keys strikes me as inconsistent:
user=> (keys "")
nil
user=> (keys "abc")
ClassCastException
Empty collections appear to be treated specially, and the test cases indicate that this is intentional. What's the thinking behind this behaviour?
The reason for this is that when a collection is converted to a sequence using seq
function, in case the collection is empty seq
will return nil rather than an empty sequence. There is another thread which discuss the reason for that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With