Caro
Caro

Reputation: 33

How to apply a function to the parameter of another function?

I have defined the following functions:

isOk :: Group -> Bool
//some condition

filterGroup :: [Group] -> [Group]
filterGroup g = filter isOk g

getGroupNb :: Group -> NoGroupe
getGroupNb (Group _ noGroupe _ _ _) = noGroupe

nbGroup :: [Group] -> [NoGroupe]
nbGroup groupX = map getGroupNb groupX

I want to apply the function filterGroup to the [Group] that is passed as a parameter to the last function nbGroup. I would like something like that, for the last function:

nbGroup :: [Group] -> [NoGroupe]
nbGroup where [Group] = filterGroup[Group]
nbGroup groupX = map getGroupNb groupX

How can I apply a function to a parameter of another function?

Upvotes: 0

Views: 137

Answers (1)

Ralph Allan Rice
Ralph Allan Rice

Reputation: 402

You could just apply the filter directly:

nbGroup :: [Group] -> [NoGroupe]
nbGroup groupX = map getGroupNb (filterGroup groupX)

Upvotes: 2

Related Questions