Skip to content

Disambiguate between decoders and transformers #25

Description

@gaku-sei

We already disambiguate between "safe" and "unsafe" decoders (the former being 1:1 with the TypeScript's types), we need to disambiguate simple decoders, and transformers.

What is a transformer?

A transformer is a decoder that will change the internal value (map for instance).

Why does it matter?

We probably don't need any documentation, and the implementation can be opaque. The main reason why we might want this, is for performance purposes. Decoders like object or record for instance, have to create a new object, because the provided decoders can be transformers. So if someone wants to do something like the following: record(({ length }) => length, str), we need to create a new object, which may have some impact on the performances. Being able to whether create an object if the decoder is a transformer, or just validate if the decoder is a simple decoder will improve performance when record is used with "normal" decoders.

Potential Issues

What about the own properties? Should we still filter out the properties that don't belong directly to the object? If we still filter them out, there will be some inconsistencies, since record(transformer) will create a new object, filtered out, and record(num) will just validate the incoming object.

See #24 for the implementation of the record decoder.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions