Effect CommunityEC
Effect Community2y ago
5 replies
Loris

Understanding Schema Transformations: Challenges with Option.getOrNull in User and SerializedUser...

Hey there, I'm trying to experiment a little bit to see how schema could work for my use case where I retrieve a User from the database, decode it into a type (e.g User) and then when I need to return the data from the API, I use an intermediate type (e.g SerializedUser) using a transformation, I'm probably doing a few things wrong because I'm new but something I don't quite understand is why in the SerializedOnboarding.transform static method I can simply call Option.getOrNull(o.nativeLanguage) and in the User.transform static method I need to call:
u.onboarding.pipe(
    Option.andThen((o) => Onboarding.encodeSync(o)),
    Option.getOrNull
 )

instead of just doing Option.getOrNull(u.onboarding) ?

Here is is the like to the full code: https://effect.website/play#d84a5c175cc2
Was this page helpful?