Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
swap i j xs = swap' withIdx
withIdx = zip [0..] xs
swap' = map f
f (idx, x) | idx == i = xs !! j
| idx == j = xs !! i
| otherwise = x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment