0

Let's assume that we have the following object:

const sample = {
  foo: {
    tags: [
      'aaa', 'bbb'
    ],
    a: 1,
    b: 10
  },
  bar: {
    tags: [
      'ccc', 'ddd'
    ],
    a: 11,
    b: 100
  }
}

How can one remove a specific tag value from object sample using ramda? I have done this

/// Remove tag named 'aaa'
R.map(v => R.assoc('tags', R.without('aaa', v.tags), v), sample)

which achieves the desired result but how can I eliminate the lamda (and the closure created) inside map ?

2 Answers 2

1

You could use evolve instead of assoc. assoc expects a property and plain value to set on provided object, whereas evolves expects a property and function producing the new value (although in a slightly other syntax).

R.map(R.evolve({tags: R.without('aaa')}), sample)
Sign up to request clarification or add additional context in comments.

Comments

1

You can R.evolve each object, and use R.without to transform the value of tags:

const { map, evolve, without } = R

const fn = map(evolve({
  tags: without('aaa')
}))

const sample = {"foo":{"tags":["aaa","bbb"],"a":1,"b":10},"bar":{"tags":["ccc","ddd"],"a":11,"b":100}}

const result = fn(sample)

console.log(result)
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.27.0/ramda.js"></script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.