only pure functions” ◦ Functions without side effects • Benefits: ◦ Increase modularity ◦ Easier to test, reuse, parallelize, generalize, and reason about 「純粋関数だけでプログラムを組み立てる」ことを前提とすることで、テ ストしやすいなどの様々な恩恵を受けられます。
◦ give up existing awesome but impure libraries? ◦ re-implement entire project? • Can’t ignore its learning cost 「だけ」というのは強力ですが、非純粋な依存ライブラリをどうするか、 学習コストが馬鹿にならない等の問題があります。
▪ Consists of pure components ▪ FP world. Easy to test, reuse, etc. ◦ FP libraries are heavily used here ▪ e.g. Cats 2つの層が浮き彫りになりました。1つは純粋層です。独立した純粋な パッケージで、関数型の恩恵を受けることができます。
and other effects. ◦ Depends on the pure layer ◦ Most dependent libraries are used here ▪ e.g. scalikejdbc もう1つは作用層で、DBアクセスなどの作用が実行されます。純粋層 に依存してロジックを実現します。
business rules ◦ Removal of effects emphasizes our core business rules ◦ Of course, they’re all easy to test, reuse, ... • We’ve started to focus on “What is our core business rule” as well as “What is pure” また純粋層は、作用を取り除いた結果、核となるビジネスルールを表 現するようになりました。関数型のメリットは残したまま。
◦ It might be time to graduate “Partially applied”, and start the original FP. ◦ Suit your project! 事業のコアとなる作用を扱いたくなったら?関数型の部分適用は卒業 して、本来の関数型を始めるときかもしれません。
pure methods, and you’ll find it’s your core business rules. References 関数型を部分的に適用するのも有用です。純粋関数を抽出すると、そ れが核となるビジネスロジックだと気付きます。 • Functional Programming in Scala • The Clean Architecture