Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created April 25, 2011 03:03
Show Gist options
  • Save jutememo/940099 to your computer and use it in GitHub Desktop.
Save jutememo/940099 to your computer and use it in GitHub Desktop.
swap i j xs = reverse $ fst $ foldl f ([],0) xs
where
f (acc, idx) x | idx == i = (xs!!j:acc, idx+1)
| idx == j = (xs!!i:acc, idx+1)
| otherwise = (x:acc, idx+1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment