Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
swap i j xs = swap' withIdx
where
withIdx = zip [0..] xs
swap' = map f
where
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