Reputation: 178
Is there a way to apply one argument to multiple functions in elm?
in the example, x
would be applied to each isDiv
function
isDiv : Int -> Int -> Bool
isDiv x y =
modBy x y == 0
isLeapYear : Int -> Bool
isLeapYear x =
x (isDiv 4 && isDiv 100 || isDiv 400)
Ended up doing this
isLeapYear : Int -> Bool
isLeapYear x =
let
isDiv y =
modBy y x == 0
in
isDiv 4 && not (isDiv 100) || isDiv 400
Upvotes: 4
Views: 112
Reputation: 36375
You could write a helper function inside isLeapYear
like this:
isLeapYear : Int -> Bool
isLeapYear x =
let isDivX n = isDiv x n
in isDivX 4 && isDivX 100 || isDivX 400
Upvotes: 4