0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Scala で empty な Seq に tail すると実行時例外になる

Last updated at Posted at 2019-01-12
scala> Seq(1, 2, 3).tail
res5: Seq[Int] = List(2, 3)

scala> Seq.empty[Int].tail
java.lang.UnsupportedOperationException: tail of empty list
  at scala.collection.immutable.Nil$.tail(List.scala:433)
  at scala.collection.immutable.Nil$.tail(List.scala:428)
  ... 40 elided

WartRemovertail -> drop(1) に変えろと言われるのはこういうことらしい。

  • こういうメジャーどころのメソッドで実行時例外が起きて
  • 代替手段が drop(1) みたいなブサイクなやつ

だと、なんか萎えるなぁという気持ち。

ちなみに Haskell も標準の List に単純に tail すると Exception を吐く。
関数型界隈で tail といえばこの動作なんだろうか??

Prelude> tail []
*** Exception: Prelude.tail: empty list
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?