Schema Decoding with External Parameters in Effect Typescript

Can a schema decoding rely on another paramter other than the Input schema? I believe what I want to do would be a one-way schema transformation, which is basically I have an Array(Product) => Product, and I need to filter the product array by Id. Then I should be able to transform the keys of the Product if I want to, right?

Or would it make more sense to have a Schema transformation defined on the Product schema itself...i think that makes more sense also.

So - can I have something like:

export const TransformedSchema = ProductsSchema.pipe(Schema.transform(Schema.Struct({
  id: ProductIdBrand,
  name: Schema.String,
  price: Schema.String,
  image: Schema.URL,
  category: Schema.String,
  description: Schema.String
}), {
  decode: (productsArray, id: ProductId) => productsArray.filter(product => product.id === id)[0] 
}


where id is what Is passed in when calling
decode
? Should be doable right? just seems maybe i'm not appraoching it right?
Was this page helpful?