I'm studying functional programming from here, and come across below code
const wasBornInCountry = person => person.birthCountry === OUR_COUNTRY
const wasNaturalized = person => Boolean(person.naturalizationDate)
const isOver18 = person => person.age >= 18
const isCitizen = person => wasBornInCountry(person) || wasNaturalized(person)
const isEligibleToVote = person => isOver18(person) && isCitizen(person)
Which can be shorten to below
const isCitizen = either(wasBornInCountry, wasNaturalized)
const isEligibleToVote = both(isOver18, isCitizen)
I can't seems to understand how
const isCitizen = person => wasBornInCountry(person) || wasNaturalized(person)
can be translated to below:
const isCitizen = either(wasBornInCountry, wasNaturalized)
How do we pass the parameter person
into wasBornInCountry
and wasNaturalized
? What if I wish to call isCitizen
with two parameters? How we know which parameter gonna be passed to wasBornInCountry
and which parameter to wasNaturalized
?