Simple question here for Clojure. Which is more idiomatic when dealing with strings? Which is more idiomatic when dealing with other data types? Which is more efficient?
(drop 1 str)
or
(rest str)
Whatever you're dealing with, rest
will be more efficient, but the difference will be so trivial as to be uninteresting.
Make sure you know whether you want rest
or next
, because in some cases it matters. rest
is lazier, and is probably right more often, but if you use rest
when you need next
the results can be hard to track down.
For strings...neither! Use subs
, the built-in substring operator:
user> (subs "hears" 1)
"ears"
rest
is fine, but it would yield a seq of characters instead of a string; usually you'll find a string easier to deal with, and it's simple enough to turn it back into a seq of characters sometime later.
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