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
30
Authorization to implement with Extensible Effect
machuz
PRO
0
360
アルプの 認証/認可分離戦略と手法
machuz
PRO
3
700
AuthzCtx - Alp社内共有会
machuz
PRO
0
65
アルプのEff独自エフェクト集 / Alp-original ’Eff’ pearls
machuz
PRO
1
1.7k
Scalebaseバックエンド構成について/the backend design of Scalebase
machuz
PRO
0
6.1k
SQL Meisterへの道 ~更新編~ / sql-meister-CUD
machuz
PRO
0
2.1k
SQL Meisterへの道 ~基礎〜参照編~ / sql-meister-R
machuz
PRO
0
2.5k
Authz
machuz
PRO
0
300
Other Decks in Programming
See All in Programming
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
Amazon Qを使ってIaCを触ろう!
maruto
0
410
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
930
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
340
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.7k
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
300
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
Realtime API 入門
riofujimon
0
150
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
610
みんなでプロポーザルを書いてみた
yuriko1211
0
280
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
The Cult of Friendly URLs
andyhume
78
6k
Thoughts on Productivity
jonyablonski
67
4.3k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Being A Developer After 40
akosma
87
590k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
A better future with KSS
kneath
238
17k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
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! ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ