I am wondering if there is an easy way to combine some of these functions together to make it a little more clean. The purpose of the function is to take an int list, and return a list containing all elements that occur after the given occurrence of an int.
listAfterFinalKey:: [Int] -> Int -> [Int]
My code works, I was just wondering if there was a better way of writing it. I would ideally like to have it all be in one function (listAfterFinalKey), but I don't know how to make it work other than having three separate functions. I am also avoiding any build in libraries, and things such as let, and where. I would appreciate if someone could show me how to combine or condense some of this code (if possible).
listAfterFinalKey:: [Int] -> Int -> [Int]
listAfterFinalKey [] x = []
listAfterFinalKey x y = helperFunction1 x y (checker x y 0)
checker:: [Int] -> Int -> Int -> Int
checker [] tracker count = count
checker (x:xs) tracker count = if tracker == x
then checker xs tracker (count+1)
else checker xs tracker count
helperFunction1:: [Int] -> Int -> Int -> [Int]
helperFunction1 [] tracker count = []
helperFunction1 x tracker count = if (count == 0)
then take 1 x ++ helperFunction1 (drop 1 x) tracker count
else if (count /= 0) && (tracker == (head x))
then helperFunction1 (drop 1 x) tracker (count-1)
else helperFunction1 (drop 1 x) tracker count
letandwhere? What about guards?listAfterFinalKey xs x = tail $ dropWhile (/=x) xs. Why "avoiding built-in libraries"?xleft. It's still a one-liner though `listAfterFinalKey xs x = (reverse . takeWhile (/= x) . reverse) xs