Skip to content

Instantly share code, notes, and snippets.

@sebabouche
Created June 22, 2018 20:15
Show Gist options
  • Save sebabouche/f670b61b3864128b35409aa79a643afe to your computer and use it in GitHub Desktop.
Save sebabouche/f670b61b3864128b35409aa79a643afe to your computer and use it in GitHub Desktop.
ramda: compose, bboth, either, gte, prop, equals, __
import { compose, both, either, gte, prop, equals, __ } from "ramda"
const OUR_COUNTRY = "France"
const wasBornInCountry = compose(
equals(OUR_COUNTRY),
prop("birthCountry"),
)
const wasNaturalized = compose(
Boolean,
prop("naturalizationDate"),
)
const isOver18 = compose(
gte(__, 18),
prop("age"),
)
const isCitizen = either(wasBornInCountry, wasNaturalized)
const isEligibleToVote = both(isOver18, isCitizen)
console.log(isCitizen({ age: 21, birthCountry: "France" }))
console.log(isEligibleToVote({ age: 21, birthCountry: "Wakanda", naturalizationDate: "someDate" }))
console.log(isEligibleToVote({ age: 16, birthCountry: "France" }))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment