Coder Social home page Coder Social logo

Comments (3)

polytypic avatar polytypic commented on September 24, 2024
    const change = R.compose(
        L.set(newRoomLens(7357), {roomType: 'DOUBLE', ratePlan: 'RAC'}),
        L.set(hotelLens(7357), {id: 7357, name: 'Hotel Opera'})
    )

What this does is that the latter operation L.set(hotelLens(...), {...}) replaces the whole object. So, what you get is an idempotent operation: no matter how many times it is applied, the result is the same as from the first application.

Continued shortly...

from partial.lenses.

polytypic avatar polytypic commented on September 24, 2024
function hotelLens(id) {
  return L.compose(
    L.prop('bookingOrder'),
    L.prop('hotels'),
    L.find(R.whereEq({id})),
    L.defaults({id})
  )
}

function nameLens(hotelId) {
  return L.compose(hotelLens(hotelId), L.prop("name"))
}

function newRoomLens(hotelId) {
  return L.compose(
    hotelLens(hotelId),
    L.prop('rooms'),
    L.append
  )
}

const change = R.compose(
  L.set(newRoomLens(7357), {roomType: 'DOUBLE', ratePlan: 'RAC'}),
  L.set(nameLens(7357), 'Hotel Opera')
)

const state = {bookingOrder: {hotels: []}}

change(change(state))

Above is one way to avoid the problem.

Setting the hotel name and adding rooms in a composed function seems a bit suspect. I would assume that one would want to first set the hotel name and then perhaps add multiple rooms.

Note that there is also a gitter channel where lens questions are certainly on topic.

from partial.lenses.

ikr avatar ikr commented on September 24, 2024

Ah, I see now. Thanks a lot for your detailed answer! I'll probably use the gitter channel quite a bit :)

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.