File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
pub/functora/src/prelude/Functora Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,8 @@ module Functora.Prelude
104
104
randomListPure ,
105
105
randomByteString ,
106
106
randomByteStringPure ,
107
+ shuffle ,
108
+ shufflePure ,
107
109
expBackOff ,
108
110
expBackOffSecondsAfter ,
109
111
secondsToNominalDiffTime ,
@@ -1084,6 +1086,21 @@ randomByteStringPure qty =
1084
1086
first BS. pack
1085
1087
. randomListPure qty
1086
1088
1089
+ shuffle :: [a ] -> IO [a ]
1090
+ shuffle xs = do
1091
+ gen <- Random. newStdGen
1092
+ pure $ shufflePure gen xs
1093
+
1094
+ shufflePure :: (Random. RandomGen g ) => g -> [a ] -> [a ]
1095
+ shufflePure _ [] = []
1096
+ shufflePure _ [x] = [x]
1097
+ shufflePure prevGen xs =
1098
+ case splitAt idx xs of
1099
+ (xs0, x : xs1) -> x : shufflePure nextGen (xs0 <> xs1)
1100
+ _ -> error " IMPOSSIBLE_SHUFFLE_PURE"
1101
+ where
1102
+ (idx, nextGen) = Random. randomR (0 , length xs - 1 ) prevGen
1103
+
1087
1104
expBackOff :: forall a . (From a Natural ) => a -> Natural
1088
1105
expBackOff = (2 ^ ) . from @ a @ Natural
1089
1106
You can’t perform that action at this time.
0 commit comments