Skip to content

Instantly share code, notes, and snippets.

@taroyanaka
Forked from sebabouche/ramda6.js
Created October 24, 2018 02:39
Show Gist options
  • Save taroyanaka/4b714a4fc6bb9f152ee00f97603c12ba to your computer and use it in GitHub Desktop.
Save taroyanaka/4b714a4fc6bb9f152ee00f97603c12ba to your computer and use it in GitHub Desktop.
ramda: objects (compose, inc, prop, assoc, evolve, always, add)
import { compose, inc, prop, assoc, evolve, always, add } from "ramda"
const nextAge = compose(
inc,
prop("age"),
)
console.log("nextAge", nextAge({ age: 21 }))
const celebrateBirthday = person => assoc("age", nextAge(person), person)
const person = { age: 24 }
console.log("celebrateBirthday", celebrateBirthday(person))
console.log("person", person)
const celebrateBirthday2 = evolve({ age: inc })
console.log("celebrateBirthday2", celebrateBirthday2(person))
const me = {
firstName: "Sébastien",
lastName: "Nicolaïdis",
birthDate: new Date("1979-09-13T15:00Z"),
age: 38,
hobbies: ["Rock climbing", "Horse riding", "Chess"],
}
const change = evolve({
firstName: always("Bob"),
lastName: always("Bob"),
userName: always("Bob"),
age: add(20),
})
console.log("(change(me)", change(me))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment