Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Latest commit

 

History

History
326 lines (188 loc) · 6.72 KB

slides.md

File metadata and controls

326 lines (188 loc) · 6.72 KB
theme background title class highlighter drawings transition mdc
default
effect meetup 20240423
text-center
shiki
persist
slide-left
true

Effect / fp-ts interoperability

A quick overview of the set of tools Inato used to migrate its codebase to Effect.


Introduction

  • Inato is a global clinical trials marketplace disrupting traditional feasibility
  • Introduced fp-ts in our codebase in 2020
ReaderTaskEither<R, E, A>
= Reader<R, TaskEither<E, A>>
= (context: R) => () => Promise<Either<E, A>>

<=> Effect<A, E, R> ~ (context: Context<R>) => E | A

layout: two-cols layoutClass: gap-16

The switch

  • Decided officially to switch from fp-ts to Effect in 2024

    • Active development will end
    • Steep learning curve
    • Lack of documentation
    • Many other points: fp-ts vs Effect

::right::


Context

  • Around 400 use cases and 80 ports and their adapters to migrate

  • Plan needed to ensure a smooth transition

  • 🎯 Objective: in 2,5 months, any new use case, port/adapters will be written using Effect


The plan

  1. Ensure our ports return ReaderTaskEither


The plan

  1. Create Effect proxies of our ports


The plan

  1. Start (re)writing use cases in Effect
  2. Create fp-ts proxies of Effect use cases


The plan

  1. Start (re)writing ports in Effect
  2. Create fp-ts proxies of Effect ports


The plan

  1. Be able to run Effect and fp-ts use cases


Example application

Representative of our codebase

<<< @/snippets/fpts.ts ts {all|5-9|11-26|28-40|42-54|55-64}{maxHeight:'80%'} twoslash


Create an Effect proxy

Use portToEffect to create an Effect proxy of an fp-ts port

<<< @/snippets/step1.ts ts {22-25|27-31|43-45|47-53|60|65-67}{maxHeight:'80%'} twoslash


Rewrite a usecase in Effect

Use effectToFpts to translate the usecase back to fp-ts for backward compatibility

<<< @/snippets/step2.ts ts {63-67|69-72|58-61}{maxHeight:'80%'} twoslash


Convert ports to Effect

Use portToFpts to create an fp-ts proxy of an Effect port for backward compatibility

<<< @/snippets/step3.ts ts {13-16|24-28|32-34|44-48|53-56}{maxHeight:'80%'} twoslash


Run the usecase the Effect way

Use contextToFpts to extract ports for backward compatibility

<<< @/snippets/step4.ts ts {30|50|71-75|77-84|70-85}{maxHeight:'80%'} twoslash


Define fp-ts mappings

FptsConvertible<T> and getFptsMapping makes it easier to use other helpers

<<< @/snippets/step5.ts ts {102-105|107|111-114|118|122-135|139-142|158-161|173-176}{maxHeight:'80%'} twoslash

Helpers recap

The helpers we used during the migrations:

  • FptsConvertible<T>: defines a fp-ts "convertible" port
  • getFptsMapping: get the fp-ts "mapping" of a convertible port
  • contextToFpts: extract ports from Effect context
  • portToEffect: creates an Effect proxy of an fp-ts port
  • effectToFpts: translates an Effect usecase to fp-ts
  • portToFpts: creates an fp-ts proxy of an Effect port
  • optionFromFpts: creates an Effect Option from fp-ts
  • eitherFromFpts: creates an Effect Either from fp-ts
  • optionTraverseEffect: Effect Option traversal

Conclusion

  • Objective accomplished in 2 months!
  • All ports migrated in around a month thanks to team work
  • All runners migrated
  • We even got rid of fp-ts options in our domain
  • Today: around 80 new full Effect use cases

Thank you!

Any questions?


Helpers recap

contextToFpts: extract ports from Effect context

<<< @/snippets/helpersRecap.ts#contextToFpts ts {maxHeight:'80%'}


Helpers recap

portToEffect: creates an Effect proxy of an fp-ts port

<<< @/snippets/helpersRecap.ts#portToEffect ts {maxHeight:'80%'}


Helpers recap

effectToFpts: translates an Effect usecase to fp-ts

<<< @/snippets/helpersRecap.ts#effectToFpts ts {maxHeight:'80%'}


Helpers recap

portToFpts: creates an fp-ts proxy of an Effect port

<<< @/snippets/helpersRecap.ts#portToFpts ts {maxHeight:'80%'}


Some more helpers

To facilitate a smooth transition for the whole team, we added some more helpers:

<<< @/snippets/moreHelpers1.ts ts {maxHeight:'80%'} twoslash


Some more helpers

We were missing the fp-ts option.traverse, so we created ours:

<<< @/snippets/moreHelpers2.ts ts {maxHeight:'80%'} twoslash