Create a gist now

Instantly share code, notes, and snippets.

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