Skip to content

Instantly share code, notes, and snippets.

@njbartlett
Created August 9, 2010 21:51
Show Gist options
  • Save njbartlett/516197 to your computer and use it in GitHub Desktop.
Save njbartlett/516197 to your computer and use it in GitHub Desktop.
-- Find the longest shared prefix of two lists
-- e.g. findPrefix [1,2,3,4] [1,2,3,5] returns [1,2,3]
findPrefix :: (Eq a) => [a] -> [a] -> [a]
findPrefix xs = map fst . takeWhile (uncurry (==)) . zip xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment