Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
The advantage of using ’Eff’ in Scala Project
Search
machu
PRO
June 28, 2019
Programming
2
13k
The advantage of using ’Eff’ in Scala Project
machu
PRO
June 28, 2019
Tweet
Share
More Decks by machu
See All by machu
NBAチームから学ぶ強いチームの作り方
machuz
PRO
0
35
Authorization to implement with Extensible Effect
machuz
PRO
0
380
アルプの 認証/認可分離戦略と手法
machuz
PRO
3
710
AuthzCtx - Alp社内共有会
machuz
PRO
0
66
アルプのEff独自エフェクト集 / Alp-original ’Eff’ pearls
machuz
PRO
1
1.8k
Scalebaseバックエンド構成について/the backend design of Scalebase
machuz
PRO
0
6.2k
SQL Meisterへの道 ~更新編~ / sql-meister-CUD
machuz
PRO
0
2.2k
SQL Meisterへの道 ~基礎〜参照編~ / sql-meister-R
machuz
PRO
0
2.5k
Authz
machuz
PRO
0
310
Other Decks in Programming
See All in Programming
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
1k
非ブラウザランタイムとWeb標準 / Non-Browser Runtimes and Web Standards
petamoriken
0
430
ドメインイベント増えすぎ問題
h0r15h0
2
570
Запуск 1С:УХ в крупном энтерпрайзе: мечта и реальность ПМа
lamodatech
0
950
DMMオンラインサロンアプリのSwift化
hayatan
0
190
快速入門可觀測性
blueswen
0
500
shadcn/uiを使ってReactでの開発を加速させよう!
lef237
0
300
PicoRubyと暮らす、シェアハウスハック
ryosk7
0
220
どうして手を動かすよりもチーム内のコードレビューを優先するべきなのか
okashoi
3
870
情報漏洩させないための設計
kubotak
5
1.3k
AHC041解説
terryu16
0
400
ESLintプラグインを使用してCDKのセオリーを適用する
yamanashi_ren01
2
240
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
32
6.4k
RailsConf 2023
tenderlove
29
970
Done Done
chrislema
182
16k
How GitHub (no longer) Works
holman
312
140k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
570
Designing Dashboards & Data Visualisations in Web Apps
destraynor
230
52k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Transcript
The advantage of using ’Eff’ in Scala Project Scala Matsuri
2019 @ma2k8 4DBMBϓϩδΣΫτͰ&⒎Λ༻͢Δར
About Me ▶Tsubasa Matsukawa - SWE&SRE at Recruit Marketing Partners
Co.,Ltd. & Quipper Co.,Ltd. @wing_007 ϦΫϧʔτϚʔέςΟϯάύʔτφʔζ݉2VJQQFSॴଐͰ 48&ͱ43&ྖҬΛ୲͍ͯ͠·͢ɻ
Our Products ▶Study Sapuri English - English learning app [
Web/iOS/Android ] ओʹελσΟαϓϦ&OHMJTIͷ։ൃΛ͍ͯ͠·͢ɻ ӳޠֶशʹڵຯ͕͋Δํੋඇ
Scala has an elegant syntactic sugar ‘for expression’. To make
the most of this force…. 4DBMBʹૉఢͳҥߏจGPS͕ࣜ͋Γ·͢ɻ ͦͷྗΛ࠷େݶར༻͢ΔͨΊʹɾɾɾ
We needed to decided which ‘types’ to primarily use to
when starting Scala projects. ࢲୡ4DBMBͷϓϩδΣΫτΛ։࢝͢ΔࡍɺओʹͲͷʮܕʯΛ ༻͢Δͷ͔ΛܾΊΔඞཁ͕͋Γ·͢ɻ
These ‘types’ are often chosen. ▶Future[A] ▶Future[Try[A]] ▶Future[E Either A]
▶EitherT[Future, E, A] ※There is also case that uses "Task" instead of "Future" ͜ͷΑ͏ͳܕ͕Α͘બΕΔͰ͠ΐ͏ɻ 'VUVSFͷΘΓʹ5BTLΛ͏͜ͱ͋Γ·͢
Our team is trying…. Eff[R, A] ࢲୡͷνʔϜͰ&⒎Λࢼ͍ͯ͠·͢
Each pros and cons were…? ͦΕͧΕͷϝϦοτσϝϦοτʁ
Future[A]
▶ Easy ॴ؆୯͞ʹਚ͖·͢ɻ Pros of Future[A]
Cons of Future[A] ▶ Rough error handling. ▶ Semaphore hard.
※Task solve Semaphore problem. ॴηϚϑΥͷ੍ޚ͕͍͠ͱɺ ΤϥʔϋϯυϦϯά͕େࡶʹ͔͠ߦ͑ͳ͍Ͱ͢ɻ
Future[Try[A]] ɹ
Pros of Future[Try[A]] ▶ Error handling is possible. ॴΤϥʔϋϯυϦϯά͕ՄೳʹͳΔͰ͢ɻ
Cons of Future[Try[A]] ▶ Only throwable can be used ▶
Syntax is not simple(Coding 'try ~ catch' every time is very troublesome. ॴΤϥʔϋϯυϦϯάʹ༻Ͱ͖Δܕ͕ 5ISPXBCMFʹݶΔͱγϯλοΫε͕ෳࡶʹͳΔͰ͢ɻ
Personally, I often use ‘Try’ when wrapping Java libraries, but
since I convert to ‘Either’, they do not appear in signatures. ݸਓతʹ5SZ+BWBϥΠϒϥϦͷ8SBQͰΑ͍͘·͕͢ɺ &JUIFSܕʹม͠ɺγάχνϟʹग़͠·ͤΜɻ
Future[E Either A]
Pros of Future[E Either A] ▶ Flexible Error handling is
possible. ▶ E is ADT can be flexible expression. ▶ Every time force error handling. ॴ5SZΑΓॊೈͳΤϥʔϋϯυϦϯά͕ ՄೳʹͳΔͰ͢ɻ
Cons of Future[E Either A] ▶ Rough error handling. ▶
Every time need to match the type even if you don't need error handling. ॴΤϥʔϋϯυϦϯά͕ ෆཁͳՕॴͰܕ߹Θ͕ͤඞཁʹͳΔͰ͢ɻ
EitherT[Future, E, A]
Pros of EitherT[Future, E, A] ▶ Can solve part of
the complexity of nesting. ॴ͋Δఔωετͯ͠ GPSࣜΛγϯϓϧʹอͯΔͰ͢ɻ
Cons of EitherT[Future, E, A] ▶ It gets slower as
types are stacked. ▶ May change results in evaluation order. ▶ Too many lift. ॴɺධՁॱͰ݁Ռ͕มΘΔՄೳੑ͕͋ΓɺϞφυ ελοΫʹ٧Ήܕ͕૿͑Δͱɺܕ߹Θ͕ͤࡶʹͳΔͰ͢ɻ
Eff[R, A]
Pros of Eff[R, A] ▶ ‘Eff’ can solve other ‘types’
disadvantage. ▶ Simple syntax. ▶ Can simply use various effects. ▶ Can solved performance problem when types are stacked. ▶ A result doesn't change for the order of evaluation. &⒎͜Ε·Ͱհͨ͠ܕͷσϝϦοτͷ େ෦ΛղফͰ͖·͢ɻ
Cons of Eff[R, A] ▶’Eff’ is very simple syntax. But
not easy. ▶ difficult effects wire. ▶ Anything is lazy evaluation. ▶ Complexity of type specification. &⒎ͷσϝϦοτɺ؆୯Ͱͳ͍Ͱ͢ɻ ͋Δఔͷ׳ΕඞཁͰ͠ΐ͏ɻ
Our project used ‘Eff’ on clean architecture. զʑͷϓϩδΣΫτͰɺ$MFBO"SDIJUFDUVSFͰઃܭ͠ɺ Ҿ͖ճ͢ܕʹ&⒎Λ༻͢ΔߏΛಋೖ͍ͯ͠·͢ɻ
͜ͷΑ͏ʹෳͷޮՌΛϑϥοτʹهड़Ͱ͖ΔͷͰɺ γϯϓϧʹهड़Ͱ͖͍ͯ·͢ɻ
How to use ‘Eff’ &⒎ͷ͍ํ Library: https://github.com/atnos-org/eff
Define ADT "%5Λఆٛ͠·͢ɻ
Define Smart-constructer "%5Λ&⒎ʹੵΉεϚʔτίϯετϥΫλΛఆٛ͠·͢ɻ
ੵΜͩ"%5Λղऍ͢ΔΠϯλϓϦλΛఆٛ͠·͢ɻ Define Interpreter
Ready to use ‘Eff’. ͜ΕͰ&⒎Λར༻͢Δ४උ͕Ͱ͖·ͨ͠ɻ
&⒎Λར༻ͨ͠ϓϩάϥϜΛॻ͖·͢ɻ Write program!!
ΠϯλϓϦλʹ͔͚ͯ&⒎Λ࣮ߦ͠·͢ɻ SVO99ͷؔͦΕͧΕJNQMJDJUDPOWFSTJPOͰੜͯ͠·͢ɻ Run program!!
‘Eff’ is Good! &⒎͍͍ͧʂʢհهࣄͱίʔυαϯϓϧష͓͖ͬͯ·͢ Introduction article: https://tech.recruit-mp.co.jp/server-side/post-18728/ɹ Code sample: https://github.com/ma2k8/eff-arch-example
Thanks! ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ