Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Eff HandsOn
Search
machu
October 25, 2018
Technology
96
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Eff HandsOn
machu
October 25, 2018
More Decks by machu
See All by machu
NBAチームから学ぶ強いチームの作り方
machuz
0
79
Authorization to implement with Extensible Effect
machuz
0
480
アルプの 認証/認可分離戦略と手法
machuz
3
820
AuthzCtx - Alp社内共有会
machuz
0
110
アルプのEff独自エフェクト集 / Alp-original ’Eff’ pearls
machuz
1
2.3k
Scalebaseバックエンド構成について/the backend design of Scalebase
machuz
0
6.6k
SQL Meisterへの道 ~更新編~ / sql-meister-CUD
machuz
0
2.4k
SQL Meisterへの道 ~基礎〜参照編~ / sql-meister-R
machuz
0
2.8k
Authz
machuz
0
330
Other Decks in Technology
See All in Technology
LLMの知識とAIエージェント
happysamurai294
0
130
GitHub、使う?使わない?
happysamurai294
0
120
E2Eってつらくないですか?E2Eの管理コストを下げる手段とその実践
akaboshinit
6
2.8k
AIがGISを代替する日:〜すべてをAIが創る時代に、私たちがFOSS4Gに関わる意味〜
lehupa
0
120
今から始めるAWS環境の暗号移行 - ポスト量子時代に備える
sato4mi
0
130
AI駆動開発におけるハーネスエンジニアリングの勘所
tsukuboshi
1
890
AI AgentによるEmbedded SREの取り組み
tgidgd
1
270
増え続けるプロダクトの品質をどう担保するか。ProductSpecとTypeScriptによる取り組み
joere
2
240
素人でもできた!AIを使った短編小説創作入門
delhi09
PRO
0
250
AIテスト自動化と評価駆動開発EDD
happysamurai294
0
110
SLOを阻む不安
sraku2159
0
160
AWSセキュリティで活用するAI機能
cmusudakeisuke
1
380
Featured
See All Featured
Visualization
eitanlees
153
17k
Writing Fast Ruby
sferik
630
63k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
430
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
The untapped power of vector embeddings
frankvandijk
2
2k
How GitHub (no longer) Works
holman
316
150k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
560
Building Better People: How to give real-time feedback that sticks.
wjessup
371
20k
Optimising Largest Contentful Paint
csswizardry
37
4k
Between Models and Reality
mayunak
4
530
Code Review Best Practice
trishagee
74
20k
BBQ
matthewcrist
90
10k
Transcript
Eff hands on
༻ޠͷઆ໌ • Monad Transformer • Extensible effect (use FreeMonad) •
˒Freer effects (use FreerMonad, Efficient Freer) • جͷจͰ more Extensible effectͱݺΜͰ͍Δ
Ϟφτϥͱͷൺֱ(ࡶ)
߹ͷॱং • ϞφυτϥϯεϑΥʔϚʔ߹ͷॱংΛೖΕସ͑Δ͜ͱ ͕Ͱ͖ͳ͍ • EffOpenUnionʹΑͬͯՄೳ
࡞༻ͷॱং • ϞφυτϥϯεϑΥʔϚʔධՁॱΛೖΕସ͑Δͱ݁Ռ͕ มΘΔ • EffมΘΒͳ͍(Writer,Eitherɺܕʹ࡞༻͢Δͷ ී௨ʹॱংʹΑͬͯܕมΘΔ͕ܭࢉͷ݁ՌมΘΒͳ͍ • ʹαϯϓϧίʔυ͕͋Δ(Haskell͚ͩͲɾɾɾ) •
https://konn-san.com/prog/haskell/extensible-effects.html
ωετπϥΠͶΜ • EnglishͰ`Future[\/[E, A]]` ΛҾ͖ճ͢Α͏ʹ͠ɺͦΕҎ্ ͷෳࡶͳܕͳΔ͘Θͳ͍Α͏ʹͯ͠ճආ͍ͯ͠Δ͕ɺ 3ͭҎ্ͷϞφυΛ߹͢Δ߹liftͰ্࣋ͪ͛ͯॲཧ͢ Δඞཁ͕͋ΔɻৗʹίϯςΩετΛҙࣝ͠ͳ͍ͱ͍͚ͣɺ ਓྨͷΈͦʹͱͯΉ͔͍ͣ͠ •
EffͰશͯϑϥοτͳforࣜͰճͤΔɻωετ͠ͳ͍ɻ
ॏ͍ • Ϟφτϥɻܕ߹ΘͤͷͨΊʹ༨ܭͳ࡞ΒΕΔ • Future[\/[E,A]] • Future[\/[E,Future[\/[E, A]]]] • Future[\/[E,Future[\/[E,
Future[\/[E, A]]]]]] • (Θ͔Γ͘͢ಉ͡ܕʹͨ͠ͷͰਖ਼֬Ͱͳ͍͕)Έ͍ͨͳײ͡Ͱελο Ϋ͍ͯ͘͠ɻੵΊੵΉ΄Ͳॏ͍ • EffOpenUnion,EfficientFreerʹΑͬͯελοΫͷʹґଘ ͠ͳ͍ఆ࣌ؒͰͷॲཧ͕Մೳ
͍ํ
ͯ͢EffʹͳΔ • ͍··ͰM[+_]ίϯςΩετͷதͰ`.right`ͯ͠`toEitherT`͠ ͍ͯͨͷ͕ͯ͢EffʹͳΔ • Future,Either,DBIO,Reader,Writer,Taskɺͯ͢ͷMonadEff ม͢Δ͜ͱ͕Ͱ͖Δ • ࠓͷॴɺOptionͱTraversalܥ(List,Seq)Ҏ֎ΛEffʹ͢ΔΑ ͏ʹ͍ͯ͠Δ
͜ͷΜΛ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._
͜Μͳײ͡Ͱ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Խ͍ͯ͠Δ
؆୯ʹΈ͑Δ͔͕ͩ ͜ΕΊͬͪΌࣗ༝ߴ͍
for { x <- Option(7) y <- DBIO.successful(x) _ <-
-\/(UseCaseError) } y ཁҧ͏ܕͷ߹͕࣮ݱͰ͖͍ͯΔ for { x <- fromOption(Option(7)) y <- fromDBIO(DBIO.successful(x)) _ <- fromEsError(-\/(UseCaseError)) } y
ࠓޙɺFujiTaskΛՃ͍ͯ͘͠
ҙ
• ܕ߹Θͤήʔ͔Β։์͞Ε͍ͯ·͕͢ɺ·ͩཧͰ͖ͯ ͳͯ͘importήʔʹͳ͍ͬͯΔ • ࡞༻ͷλάͷཧ͕Ͱ͖͍ͯͳ͍
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
࡞༻λάᶃ • 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) • ಉ͡λάΛෳࢦఆ͢Δ͜ͱͰ͖ͳ͍
࡞༻λάᶄ • ࢦఆͨ͠λά(࡞༻)ΛҰͭҰͭධՁ͍ͯ͘͠ɻ • DBIOStack, ModelApplyStack, PushIOStackͷධՁҎԼͷΑ͏ʹͳΔ useCaseRes.runTransactionDBIO .runIdGen .runJodaTimeM
.runPushIO .runEsError .runAsync .runAsync .map(startCallPresenter.response) • ͜Ε `run` ͚ͩͰࡁΉΑ͏࣮ݧத
࡞༻λάᶅ • ͜ͷλάؔͷγάχνϟͱͯ͠Ҿ͖ճ͞ͳ͍ͱ͍͚ͳ ͍ def execute[R: _dbio: _task: _errorEither: _pushio:
_idgen: _jodaTimem]( arg: StartCallUseCaseArgs )(implicit ec: ExecutionContext): Eff[R, StartCallUseCaseResult]
͜ΕΒमਖ਼தͰ͢
˒YATTEIKI˒