Created
November 15, 2020 19:11
-
-
Save acdimalev/ede65bb62f1c61f7a1509cf6ffb9f4c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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