Effect CommunityEC
Effect Community•3y ago•
22 replies
qlonik

Understanding Encoding/Decoding Flow with Schema Compositions and Transformations

Hey, I don't think I still got the proper mental model with schema compositions
and transformations. Can I get that straightened? 😃

Given this example,

const t = Schema.transform(
  Schema.string.pipe(Schema.brand('integer')),
  Schema.number.pipe(Schema.brand('id')),
  /*f1*/ s => 0,
  /*f2*/ n => '0'
);


How does encoding/decoding work with the functions f1 and f2?

Do I understand correctly that the decoding flow here is to use decode of the
first codec, then decode using function f1, and then use decode of the second
codec? And the encoding happening backwards: we first call encode of the second
codec, then the function f2 gets called, and then we are calling encode of the
first codec?
Was this page helpful?