theme | background | title | class | highlighter | drawings | transition | mdc | |
---|---|---|---|---|---|---|---|---|
default |
effect meetup 20240423 |
text-center |
shiki |
|
slide-left |
true |
A quick overview of the set of tools Inato used to migrate its codebase to Effect.
- 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
-
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::
-
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
- Ensure our ports return ReaderTaskEither
- Create Effect proxies of our ports
- Start (re)writing use cases in Effect
- Create fp-ts proxies of Effect use cases
- Start (re)writing ports in Effect
- Create fp-ts proxies of Effect ports
- Be able to run Effect and fp-ts use cases
Representative of our codebase
<<< @/snippets/fpts.ts ts {all|5-9|11-26|28-40|42-54|55-64}{maxHeight:'80%'} twoslash
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
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
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
Use contextToFpts
to extract ports for backward compatibility
<<< @/snippets/step4.ts ts {30|50|71-75|77-84|70-85}{maxHeight:'80%'} twoslash
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
The helpers we used during the migrations:
FptsConvertible<T>
: defines afp-ts
"convertible" portgetFptsMapping
: get thefp-ts
"mapping" of a convertible portcontextToFpts
: extract ports from Effect contextportToEffect
: creates an Effect proxy of anfp-ts
porteffectToFpts
: translates an Effect usecase tofp-ts
portToFpts
: creates anfp-ts
proxy of an Effect portoptionFromFpts
: creates an EffectOption
fromfp-ts
eitherFromFpts
: creates an EffectEither
fromfp-ts
optionTraverseEffect
: EffectOption
traversal
- 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
Any questions?
contextToFpts
: extract ports from Effect context
<<< @/snippets/helpersRecap.ts#contextToFpts ts {maxHeight:'80%'}
portToEffect
: creates an Effect proxy of an fp-ts
port
<<< @/snippets/helpersRecap.ts#portToEffect ts {maxHeight:'80%'}
effectToFpts
: translates an Effect usecase to fp-ts
<<< @/snippets/helpersRecap.ts#effectToFpts ts {maxHeight:'80%'}
portToFpts
: creates an fp-ts
proxy of an Effect port
<<< @/snippets/helpersRecap.ts#portToFpts ts {maxHeight:'80%'}
To facilitate a smooth transition for the whole team, we added some more helpers:
<<< @/snippets/moreHelpers1.ts ts {maxHeight:'80%'} twoslash
We were missing the fp-ts option.traverse
, so we created ours:
<<< @/snippets/moreHelpers2.ts ts {maxHeight:'80%'} twoslash