Create a gist now

Instantly share code, notes, and snippets.

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