We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
例として、 Seq(1, 2, 3).filter(i => i%2 == 0).headOption を Seq(1, 2, 3).find(i => i % 2) に置換するルールについて考える。 i => i%2 == 0 は副作用を持たない式なので、このまま置換しても問題ない。 しかし、 (i: Int) => {println(i); i%2 == 0} だとどうだろうか。この場合、 2 がヒットした時点で処理が完了してしまうため、 println(3) が実行されない。
Seq(1, 2, 3).filter(i => i%2 == 0).headOption
Seq(1, 2, 3).find(i => i % 2)
i => i%2 == 0
(i: Int) => {println(i); i%2 == 0}
2
println(3)
scalafix でコレクションのメソッド置換を行う場合には、渡されている関数に副作用があるか注意する必要があるため、そのメソッドを作成したい。
The text was updated successfully, but these errors were encountered:
参考: https://github.com/JetBrains/intellij-scala/blob/idea213.x/scala/scala-impl/src/org/jetbrains/plugins/scala/codeInspection/collections/package.scala#L432-L515
Sorry, something went wrong.
https://pavelfatin.com/scala-collections-tips-and-tricks/#side-effects
呼び出し関数内まで全てチェックするのは現実的ではないので、ラムダ式で完結してる部分だけで作るのが丸そう
No branches or pull requests
例として、
Seq(1, 2, 3).filter(i => i%2 == 0).headOption
をSeq(1, 2, 3).find(i => i % 2)
に置換するルールについて考える。i => i%2 == 0
は副作用を持たない式なので、このまま置換しても問題ない。しかし、
(i: Int) => {println(i); i%2 == 0}
だとどうだろうか。この場合、2
がヒットした時点で処理が完了してしまうため、println(3)
が実行されない。scalafix でコレクションのメソッド置換を行う場合には、渡されている関数に副作用があるか注意する必要があるため、そのメソッドを作成したい。
The text was updated successfully, but these errors were encountered: