Last active
October 24, 2018 02:39
-
-
Save sebabouche/e52b118296a1038c5a4bff8372f65f43 to your computer and use it in GitHub Desktop.
ramda: objects (compose, inc, prop, assoc, evolve, always, add)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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