-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtras.elm
47 lines (31 loc) · 939 Bytes
/
Extras.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module Extras exposing (..)
import Random.Pcg as Random exposing (Seed)
shuffle : Seed -> List a -> List a
shuffle seed list =
let
length =
List.length list
randomTags =
Random.step (Random.list length (Random.int 0 length)) seed
|> Tuple.first
in
List.map2 (,) randomTags list |> List.sortBy Tuple.first |> List.unzip |> Tuple.second
-- from https://github.com/elm-community/list-extra
find : (a -> Bool) -> List a -> Maybe a
find predicate list =
case list of
[] ->
Nothing
first :: rest ->
if predicate first then
Just first
else
find predicate rest
-- from https://github.com/elm-community/maybe-extra
orElseLazy : (() -> Maybe a) -> Maybe a -> Maybe a
orElseLazy fma mb =
case mb of
Nothing ->
fma ()
Just _ ->
mb