aboutsummaryrefslogtreecommitdiff
path: root/src/Utils.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/Utils.elm')
-rw-r--r--src/Utils.elm42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/Utils.elm b/src/Utils.elm
new file mode 100644
index 0000000..0f3164f
--- /dev/null
+++ b/src/Utils.elm
@@ -0,0 +1,42 @@
1module Utils exposing (..)
2
3import Array as A exposing (..)
4import Base exposing (Word, WordStatus(..))
5import Time exposing (Posix, posixToMillis)
6
7
8isNothing : Maybe a -> Bool
9isNothing p =
10 case p of
11 Nothing ->
12 True
13
14 Just a ->
15 False
16
17
18isJust : Maybe a -> Bool
19isJust p =
20 not (isNothing p)
21
22
23flip : (a -> b -> c) -> (b -> a -> c)
24flip f =
25 \x y -> f y x
26
27
28diffDuration : Posix -> Posix -> Float
29diffDuration t1 t2 =
30 let
31 m1 =
32 posixToMillis t1
33
34 m2 =
35 posixToMillis t2
36 in
37 toFloat (m2 - m1) / 1000
38
39
40wordCountWith : Array Word -> (WordStatus -> Bool) -> Int
41wordCountWith words predicate =
42 words |> A.map .status |> A.filter predicate |> A.length