Skip to content

Instantly share code, notes, and snippets.

@acdimalev
Created November 15, 2020 19:11
Show Gist options
  • Save acdimalev/ede65bb62f1c61f7a1509cf6ffb9f4c4 to your computer and use it in GitHub Desktop.
Save acdimalev/ede65bb62f1c61f7a1509cf6ffb9f4c4 to your computer and use it in GitHub Desktop.
import Optics
import Control.Monad.Random
headSwap :: [Int] -> Int -> [Int]
headSwap xs i =
xs
& (ix 0) .~ (xs !! i)
& (ix i) .~ (xs !! 0)
headSwapRand :: MonadRandom m => [Int] -> m [Int]
headSwapRand xs = do
n <- getRandomR (0, (length xs) - 1)
return $ headSwap xs n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment