Skip to content
New issue

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

副作用のある式を判定できるようにする #9

Open
Javakky-pxv opened this issue Mar 14, 2022 · 3 comments
Open

副作用のある式を判定できるようにする #9

Javakky-pxv opened this issue Mar 14, 2022 · 3 comments

Comments

@Javakky-pxv
Copy link
Contributor

例として、 Seq(1, 2, 3).filter(i => i%2 == 0).headOptionSeq(1, 2, 3).find(i => i % 2) に置換するルールについて考える。
i => i%2 == 0 は副作用を持たない式なので、このまま置換しても問題ない。
しかし、 (i: Int) => {println(i); i%2 == 0} だとどうだろうか。この場合、 2 がヒットした時点で処理が完了してしまうため、 println(3) が実行されない。

scalafix でコレクションのメソッド置換を行う場合には、渡されている関数に副作用があるか注意する必要があるため、そのメソッドを作成したい。

@Javakky-pxv
Copy link
Contributor Author

@Javakky-pxv
Copy link
Contributor Author

呼び出し関数内まで全てチェックするのは現実的ではないので、ラムダ式で完結してる部分だけで作るのが丸そう

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant