Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
swap i j xs = reverse $ fst $ foldl f ([],0) xs
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