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
Tauriでネイティブアプリを作りたい
tsucchinoko
0
360
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
Content Security Policy入門 セキュリティ設定と 違反レポートのはじめ方 / Introduction to Content Security Policy Getting Started with Security Configuration and Violation Reporting
uskey512
1
510
Outline View in SwiftUI
1024jp
1
310
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.1k
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
950
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
110
イベント駆動で成長して委員会
happymana
1
300
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
150
[PyCon Korea 2024 Keynote] 커뮤니티와 파이썬, 그리고 우리
beomi
0
120
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.2k
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
5
1.4k
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
710
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
43
2.2k
Code Review Best Practice
trishagee
64
17k
Building Applications with DynamoDB
mza
90
6.1k
Building an army of robots
kneath
302
42k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Statistics for Hackers
jakevdp
796
220k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
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! ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ