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
たのしいparse.y
ydah
3
120
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
260
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
700
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
530
暇に任せてProxmoxコンソール 作ってみました
karugamo
1
720
第5回日本眼科AI学会総会_AIコンテスト_3位解法
neilsaw
0
170
42 best practices for Symfony, a decade later
tucksaun
1
180
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
200
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
330
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
300
CSC305 Lecture 26
javiergs
PRO
0
140
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
243
12k
Embracing the Ebb and Flow
colly
84
4.5k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Site-Speed That Sticks
csswizardry
2
190
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
BBQ
matthewcrist
85
9.4k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
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! ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ