Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Eff HandsOn

machu
October 25, 2018

Eff HandsOn

machu

October 25, 2018
Tweet

More Decks by machu

Other Decks in Technology

Transcript

  1. ༻ޠͷઆ໌ • Monad Transformer • Extensible effect (use FreeMonad) •

    ˒Freer effects (use FreerMonad, Efficient Freer) • جͷ࿦จͰ͸ more Extensible effectͱݺΜͰ͍Δ
  2. ॏ͍ • Ϟφτϥ͸཯଎ɻܕ߹ΘͤͷͨΊʹ༨ܭͳ૚΋࡞ΒΕΔ • Future[\/[E,A]] • Future[\/[E,Future[\/[E, A]]]] • Future[\/[E,Future[\/[E,

    Future[\/[E, A]]]]]] • (Θ͔Γ΍͘͢ಉ͡ܕʹͨ͠ͷͰਖ਼֬Ͱ͸ͳ͍͕)Έ͍ͨͳײ͡Ͱελο Ϋ͍ͯ͘͠ɻੵΊ͹ੵΉ΄Ͳॏ͍ • Eff͸OpenUnion,EfficientFreerʹΑͬͯελοΫͷ਺ʹґଘ ͠ͳ͍ఆ਺࣌ؒͰͷॲཧ͕Մೳ
  3. ͜ͷ΁ΜΛimport import org.atnos.eff.Eff import org.atnos.eff.syntax.all._ import org.atnos.eff.addon.scalaz.either._ import org.atnos.eff.addon.monix.task._ import

    jp.eigosapuri.es.shared.lib.eff.either.EsErrorEffect._ import jp.eigosapuri.es.shared.adapter.secondary.eff._ import jp.eigosapuri.es.shared.adapter.secondary.eff.push.PushIOEffect._ import jp.eigosapuri.es.shared.adapter.secondary.eff.db.DBIOEffect._
  4. ͜Μͳײ͡ͰEffԽ override def resolveById[R: _dbio]( id: CallPreparationId )(implicit ec: ExecutionContext):

    Eff[R, Option[CallPreparation]] = { for { resOpt <- fromDBIO(callPreparationStatusesDAO.ioFindById(id.value)) } yield resOpt.map(convertToDomainModel) } fromDBIOͰEffԽ͍ͯ͠Δ
  5. for { x <- Option(7) y <- DBIO.successful(x) _ <-

    -\/(UseCaseError) } y ཁ͸ҧ͏ܕͷ߹੒͕࣮ݱͰ͖͍ͯΔ for { x <- fromOption(Option(7)) y <- fromDBIO(DBIO.successful(x)) _ <- fromEsError(-\/(UseCaseError)) } y
  6. importήʔ • EffܥͷύοέʔδΛimport͠ͳ͍ͱ͍͚ͳ͍ • Scalaz΍ɺxxExtensionͱಉ͡ϊϦͰ͢ • ΋͏ͪΐ͍੔ཧͯ͠ҰՕॴimport͢Ε͹͢΂͕͍ͯͭͯ͘ΔΑ͏ʹ͠·͢ • ۩ମతʹ͸ҎԼͷύοέʔδ import

    org.atnos.eff.Eff import org.atnos.eff.syntax.all._ import org.atnos.eff.addon.scalaz.either._ import org.atnos.eff.addon.monix.task._ import jp.eigosapuri.es.shared.lib.eff._ import jp.eigosapuri.es.shared.lib.eff.cache.CacheIOTypes._ import jp.eigosapuri.es.shared.lib.eff.push.PushIOTypes._ import jp.eigosapuri.es.shared.lib.eff.util.clock.joda.JodaTimeMEffect._ import jp.eigosapuri.es.shared.lib.eff.util.idGen.IdGenEffect._ import jp.eigosapuri.es.shared.lib.eff.either.EsErrorEffect._ import jp.eigosapuri.es.shared.adapter.secondary.eff._ import jp.eigosapuri.es.shared.adapter.secondary.eff.push.PushIOEffect._ import jp.eigosapuri.es.shared.adapter.secondary.eff.db.DBIOEffect._ import jp.eigosapuri.es.shared.adapter.secondary.eff.push.CacheIOInterpretationTypes._ import jp.eigosapuri.es.shared.adapter.secondary.eff.cache.interpreter.CacheIOInterpreter import jp.eigosapuri.es.shared.adapter.secondary.eff.db.interpreter.DBIOInterpreter import jp.eigosapuri.es.shared.adapter.secondary.eff.push.interpreter.PushIOInterpreter
  7. ࡞༻λάᶃ • EffͰ͸Ͳͷ࡞༻ΛؚΉ͔Λࢦఆ͢Δඞཁ͕͋Δ • ྫ͑͹ɺDBIOͱIdGen,JodaTime,PushΛར༻͢Δ৔߹͸ type R = FxAppend[DBIOStack, FxAppend[ModelApplyStack,

    PushIOStack]] • ͦΕͧΕͷத਎ type DBIOStack = Fx.fx3[DBIO, Task, ErrorEither] type ModelApplyStack = Fx.fx2[IdGen, JodaTimeM] type PushIOStack = Fx.fx1[PushIO] • ͜ͷΑ͏ʹ͋Δఔ౓ͷ୯ҐͰ·ͱΊΒΕͨStackΛFxAppendͰ͕ͬͪΌΜ͜ Ͱ͖Δɻޙ͸ͷΑ͏ʹUseCaseʹ౉࣮ͯ͠ߦ͢Δ͚ͩ startCallUseCase.execute[R](arg) • ಉ͡λάΛෳ਺ࢦఆ͢Δ͜ͱ͸Ͱ͖ͳ͍
  8. ࡞༻λάᶅ • ͜ͷλά͸ؔ਺ͷγάχνϟͱͯ͠Ҿ͖ճ͞ͳ͍ͱ͍͚ͳ ͍ def execute[R: _dbio: _task: _errorEither: _pushio:

    _idgen: _jodaTimem]( arg: StartCallUseCaseArgs )(implicit ec: ExecutionContext): Eff[R, StartCallUseCaseResult]