この記事では、Scala 3と関数型ライブラリであるCatsを時折使いつつ、Stateモナドを利用することでmap結果にうるおいを与えられるという話題を紹介します。 よくある処理: mapしてからペアにする まあまあよくある: メソッドはたまに値返さないことがある まあまあよくある: メソッドが非同期の場合もある Stateモナド 通常の関数をStateに持ち上げる Stateでmapする StateT登場!! 一般化する まとめ プログラミング言語で最も頻繁に使われるデータ構造といえば、タプル、とりわけ2つの要素を持つタプルであるペアかもしれない。 【タプルとは?】 タプルとは、いくつかの型を並べて組にし、1つの型として扱えるようにしたものです。例えば、StringとIntをくっつけた(String, Int)というタプルを考えることができます。 タプルを構成する型の数によって、3-タプ