Created
June 22, 2018 20:15
-
-
Save sebabouche/f670b61b3864128b35409aa79a643afe to your computer and use it in GitHub Desktop.
ramda: compose, bboth, either, gte, prop, equals, __
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, 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