The advantage of using ’Eff’ in Scala Project

C6a8cb5e13aa716521d522471ec4e4cd?s=47 ma2k8
June 28, 2019

The advantage of using ’Eff’ in Scala Project

C6a8cb5e13aa716521d522471ec4e4cd?s=128

ma2k8

June 28, 2019
Tweet

Transcript

  1. 1.

    The advantage of using ’Eff’ in Scala Project Scala Matsuri

    2019 @ma2k8 4DBMBϓϩδΣΫτͰ&⒎Λ࢖༻͢Δར఺
  2. 2.

    About Me ▶Tsubasa Matsukawa - SWE&SRE at Recruit Marketing Partners

    Co.,Ltd. & Quipper Co.,Ltd. @wing_007 ϦΫϧʔτϚʔέςΟϯάύʔτφʔζ݉2VJQQFSॴଐͰ 48&ͱ43&ྖҬΛ୲౰͍ͯ͠·͢ɻ
  3. 3.

    Our Products ▶Study Sapuri English - English learning app [

    Web/iOS/Android ] ओʹελσΟαϓϦ&OHMJTIͷ։ൃΛ͍ͯ͠·͢ɻ ӳޠֶशʹڵຯ͕͋Δํ͸ੋඇ
  4. 4.

    Scala has an elegant syntactic sugar ‘for expression’. To make

    the most of this force…. 4DBMBʹ͸ૉఢͳ౶ҥߏจGPS͕ࣜ͋Γ·͢ɻ ͦͷྗΛ࠷େݶར༻͢ΔͨΊʹɾɾɾ
  5. 5.

    We needed to decided which ‘types’ to primarily use to

    when starting Scala projects. ࢲୡ͸4DBMBͷϓϩδΣΫτΛ։࢝͢ΔࡍɺओʹͲͷʮܕʯΛ ࢖༻͢Δͷ͔ΛܾΊΔඞཁ͕͋Γ·͢ɻ
  6. 6.

    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Λ࢖͏͜ͱ΋͋Γ·͢
  7. 11.

    Cons of Future[A] ▶ Rough error handling. ▶ Semaphore hard.

    ※Task solve Semaphore problem. ୹ॴ͸ηϚϑΥͷ੍ޚ͕೉͍͠఺ͱɺ ΤϥʔϋϯυϦϯά͕େࡶ೺ʹ͔͠ߦ͑ͳ͍఺Ͱ͢ɻ
  8. 14.

    Cons of Future[Try[A]] ▶ Only throwable can be used ▶

    Syntax is not simple(Coding 'try ~ catch' every time is very troublesome. ୹ॴ͸ΤϥʔϋϯυϦϯάʹ࢖༻Ͱ͖Δܕ͕ 5ISPXBCMFʹݶΔ఺ͱγϯλοΫε͕ෳࡶʹͳΔ఺Ͱ͢ɻ
  9. 15.

    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ܕʹม׵͠ɺγάχνϟʹ͸ग़͠·ͤΜɻ
  10. 17.

    Pros of Future[E Either A] ▶ Flexible Error handling is

    possible. ▶ E is ADT can be flexible expression. ▶ Every time force error handling. ௕ॴ͸5SZΑΓ΋ॊೈͳΤϥʔϋϯυϦϯά͕ ՄೳʹͳΔ఺Ͱ͢ɻ
  11. 18.

    Cons of Future[E Either A] ▶ Rough error handling. ▶

    Every time need to match the type even if you don't need error handling. ୹ॴ͸ΤϥʔϋϯυϦϯά͕ ෆཁͳՕॴͰ΋ܕ߹Θ͕ͤඞཁʹͳΔ఺Ͱ͢ɻ
  12. 20.

    Pros of EitherT[Future, E, A] ▶ Can solve part of

    the complexity of nesting. ௕ॴ͸͋Δఔ౓ωετͯ͠΋ GPSࣜΛγϯϓϧʹอͯΔ఺Ͱ͢ɻ
  13. 21.

    Cons of EitherT[Future, E, A] ▶ It gets slower as

    types are stacked. ▶ May change results in evaluation order. ▶ Too many lift. ୹ॴ͸཯଎໰୊ɺධՁॱͰ݁Ռ͕มΘΔՄೳੑ͕͋ΓɺϞφυ ελοΫʹ٧Ήܕ͕૿͑Δͱɺܕ߹Θ͕ͤ൥ࡶʹͳΔ఺Ͱ͢ɻ
  14. 22.
  15. 23.

    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. &⒎͸͜Ε·Ͱ঺հͨ͠ܕͷσϝϦοτͷ େ෦෼ΛղফͰ͖·͢ɻ
  16. 24.

    Cons of Eff[R, A] ▶’Eff’ is very simple syntax. But

    not easy. ▶ difficult effects wire. ▶ Anything is lazy evaluation. ▶ Complexity of type specification. &⒎ͷσϝϦοτ͸ɺ؆୯Ͱ͸ͳ͍఺Ͱ͢ɻ ͋Δఔ౓ͷ׳Ε͸ඞཁͰ͠ΐ͏ɻ