問題タブ [scala-cats]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
scala - 無料のモナドからの生成
私が理解している限り、無料の構築では、任意の Functor を Monad に持ち上げることができます。Cats ライブラリを使用すると、ファンクター インスタンスを提供しなくても、この ADT をモナドに持ち上げることができます。
Free が定義されている場合の従来の (単純な) アプローチでも
継続して ADT をエンコードする必要があります。
Cats を使用している場合、cont パラメーターを指定する必要はありません。なぜですか?
scala - Refactoring an OOP "decorator" to Free monad structure(s)
I have a bit of “legacy” Scala code (Java-like), which does a bit of data access. There’s a decorator which tracks usage of the DAO methods (collecting metrics), like this:
I'm trying to model this as a Free monad. I've defined the following algebra for the DAO operations:
I see two options:
a) I can either make two interpreters that take DBOp
, one performs the actual data access, the other does the tracking, and compose them together OR
b) I make Tracking an explicit algebra, and use a Coproduct to use them both in the same for
composition OR
c) Something completely different!
The first option looks more like a "decorator" approach, which is tied to DBOp
, the second is more generic solution, but would require calling the 'tracking' algebra explicitly.
In addition, notice the source
parameter on the original fetchById
call: it's only used for tracking. I much rather remove it from the API.
Here's the actual question: how do I model the tracking?
scala - モノイドによる誤差の蓄積
E => Either[Exception, Unit]
イベント時に呼び出し、E
返すエラーを蓄積する関数のリストがあるとしEither[List[Exception], Unit]
ます。
fire
で実装したいcats
それは理にかなっていますか?どのように改善しますか?同時に呼び出す
ように変更するには?fire
subscribers