 Writing in terms of HoF

Hi, a small question about some HoFs

I got a function, split, that uses recursion
it works as follows:
split ‘a’, “amandesas” = [“m”, "ndes, “s”]

How can I write this using HoF?
filter (/= a) xs kinda gets in the direction but isnt quite it

This might come handy:

λ> :m +Data.List
λ> :t groupBy
groupBy :: (a -> a -> Bool) -> [a] -> [[a]]

oo thankss that looks real handy

map (filter (/= ‘a’))( groupBy (/=) “alabamasong”)

this work! thank you for introducing groupBy lol

1 Like

Unfortunately that is not a solution, e.g. try the input: “blabamasong”, and see what the output is (I think it is not what you want).

The behavior of groupBy can be very strange if its first argument is not a proper equivalence relation (/= is not an equivalence relation).

I would suggest using more traditional functions like span :: (a -> Bool) -> [a] -> ([a], [a]) or break :: (a -> Bool) -> [a] -> ([a], [a]) in a recursive function to solve this exercise.

If you really want to use groupBy then an equivalence relation that you can use is (==) `on` (== 'a') (with on from Data.Function) or equivalently \x y -> (x == 'a') == (y == 'a').