Coder Social home page Coder Social logo

Comments (3)

polytypic avatar polytypic commented on June 17, 2024 1

In case you only want a unidirectional operation, you can freely compose optics with functions. So, you could say (playground):

L.get(
  L.pick({
    stuff: L.collect(['a', L.elems, L.props('b')]),
    otherStuff: ['d', 'e']
  }),
  data)

Above L.collect(...) results in an ordinary function that will be used as a read-only optic.

The company example uses the above technique in one half of the joinView isomorphism constructor.

BTW, the Gitter channel is also good for questions like this.

from partial.lenses.

elysion avatar elysion commented on June 17, 2024 1

Oh, did not realize I could use functions like that or use Gitter. Using functions in the lenses do solve the problems I currently have as I do not need to use the lense in the other direction. Being able to use the traversals with pick in both directions sounds like something that could be useful in other cases.

from partial.lenses.

polytypic avatar polytypic commented on June 17, 2024

I just realized that there is likely a better way to handle this case. What you are actually looking for here is a kind of adapter between two forms of the same data. We can express that using isomorphisms. Here is a playground that does just that. In this case the adapter is lossy, but notice that the adapter works in both directions. I'll add the array iso constructor to the library when I have a moment.

from partial.lenses.

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.