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
31
Authorization to implement with Extensible Effect
machuz
PRO
0
370
アルプの 認証/認可分離戦略と手法
machuz
PRO
3
700
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
300
Other Decks in Programming
See All in Programming
Recoilを剥がしている話
kirik
5
6.7k
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
220
暇に任せてProxmoxコンソール 作ってみました
karugamo
2
720
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
130
Effective Signals in Angular 19+: Rules and Helpers
manfredsteyer
PRO
0
100
テストコード書いてみませんか?
onopon
2
110
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
280
php-conference-japan-2024
tasuku43
0
290
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
130
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
550
Featured
See All Featured
Side Projects
sachag
452
42k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Producing Creativity
orderedlist
PRO
341
39k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
Visualization
eitanlees
146
15k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Practical Orchestrator
shlominoach
186
10k
Docker and Python
trallard
42
3.1k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Agile that works and the tools we love
rasmusluckow
328
21k
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! ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ