Skip to content

Instantly share code, notes, and snippets.

@taroyanaka
Forked from sebabouche/ramda0.js
Created October 24, 2018 02:38
Show Gist options
  • Save taroyanaka/02c219fbd7681a6e0c68f96b821977fd to your computer and use it in GitHub Desktop.
Save taroyanaka/02c219fbd7681a6e0c68f96b821977fd 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