I have a function that, simplifying a little, looks like this:

  fn :: [a] -> a
  fn = (head .) . takeWhile $ (\_ -> True)

From this, I want a function with the signature fn' :: [(x,a)] -> (x,a) such that:

    snd $ fn' (zip [x] [a]) = fn [a]

I can see ways of doing this by altering fn, or by repeating some of fn in the definition of fn', or (because in this case I know that if fn xs = x, fn is returning the first x in xs and not any others), by doing something nasty like:

  fn' xs = xs !! fromMaybe 0 (findIndex (\(_,a) -> a == fn (snd $ unzip xs)) xs )

But it seems to me like there should be prettier solutions to this (that do not involve changing the definition of fn). After all, this doesn't seem like a rare pattern.

Anyone know if in fact there's a better way to go about it?