2

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)

それは理にかなっていますか?どのように改善しますか?同時に呼び出す
ように変更するには?firesubscribers

4

1 に答える 1