GithubHelp home page GithubHelp logo

Comments (3)

nvie avatar nvie commented on May 18, 2024

There is no direct way of doing this without cluttering up the API and using the field() construct in many other places.

A way that is currently possible is to decode the “original” fields from the source object first, and then “map” the successfully decoded result by a transformer function to the intended output structure. For example:

type Output = {
  a: string,
  b: number,
}

const decoder: Decoder<Output> = map(
  object({
    a: string,
    c: number,
  }),
  obj => ({ ...obj, b: obj.c }),
);

from decoders.

nvie avatar nvie commented on May 18, 2024

The API you suggested is something I thought about, but it would require special knowledge about the field decoder inside the object decoder (so it has implications for composability). It also has implications for annotating error messages inline, which would then need special treatment. I don’t think it’s impossible, but it would definitely be harder to implement. That’s why I haven’t found a better solution for this yet.

from decoders.

github-actions avatar github-actions commented on May 18, 2024

We have detected this issue has not had any activity during the last 60 days. That could mean this issue is no longer relevant and/or nobody has found the necessary time to address the issue. We are trying to keep the list of open issues limited to those issues that are relevant to the majority and to close the ones that have become 'stale' (inactive). If no further activity is detected within the next 14 days, the issue will be closed automatically.
If new comments are are posted and/or a solution (pull request) is submitted for review that references this issue, the issue will not be closed. Closed issues can be reopened at any time in the future. Please remember those participating in this open source project are volunteers trying to help others and creating a better collaboration environment for all. Thank you for your continued involvement and contributions!

from decoders.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.