E => Either[Exception, Unit]
イベント時に呼び出し、E
返すエラーを蓄積する関数のリストがあるとしEither[List[Exception], Unit]
ます。
type EventHandler = E => Either[Exception, Unit]
import cats.data.NonEmptyList
def fire(
e: Event,
subscribers: List[EventHandler]
): Either[NonEmptyList[Exception], Unit] = ???
fire
で実装したいcats
import cats.implicits._
subscribers.foldMap (_ map (_.toValidatedNel))
.map (.toEither)
.apply(e)
それは理にかなっていますか?どのように改善しますか?同時に呼び出す
ように変更するには?fire
subscribers