alexandru / scala-best-practices

A collection of Scala best practices
4.39k stars 623 forks source link

Add `2.20 Must not use Seq.head` rule #51

Closed valydia closed 6 years ago

valydia commented 6 years ago

Fixes https://github.com/alexandru/scala-best-practices/issues/50

wookietreiber commented 6 years ago

You can also note the +: extractor for Seq:

val xs = Seq.range(0, 10)

xs match {
  case head +: tail => println(head)
  case _            => println("meh")
}
wookietreiber commented 6 years ago

Also, head is defined on GenTraversable, so you might want to widen the scope.

alexandru commented 6 years ago

IMO most people don't know of GenTraversable.

I did not even know of the +: extractor, never used it 😲

valydia commented 6 years ago

Thanks @wookietreiber , I've added an example with the extractor +:

wookietreiber commented 6 years ago

LGTM.

valydia commented 6 years ago

Thanks for the feedbacks! I removed the alternative using the extractor +: 👍

valydia commented 6 years ago

Hello there! Is there anything on my end that I can do to help this PR being merged?

speedcom commented 6 years ago

This should be merged