diff options
author | Akshay <[email protected]> | 2020-11-22 11:03:45 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2020-11-22 11:03:45 +0000 |
commit | 75afe1122a87c4508d4a134cea697bf334e80850 (patch) | |
tree | 53b89a9a8825eb59ab18d713ae4e0d92d9edb76f /src/Utils.elm | |
parent | b90171e1f1862885a1efdfb915869eb5fad13b01 (diff) |
refactor main into modules
Diffstat (limited to 'src/Utils.elm')
-rw-r--r-- | src/Utils.elm | 42 |
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 @@ | |||
1 | module Utils exposing (..) | ||
2 | |||
3 | import Array as A exposing (..) | ||
4 | import Base exposing (Word, WordStatus(..)) | ||
5 | import Time exposing (Posix, posixToMillis) | ||
6 | |||
7 | |||
8 | isNothing : Maybe a -> Bool | ||
9 | isNothing p = | ||
10 | case p of | ||
11 | Nothing -> | ||
12 | True | ||
13 | |||
14 | Just a -> | ||
15 | False | ||
16 | |||
17 | |||
18 | isJust : Maybe a -> Bool | ||
19 | isJust p = | ||
20 | not (isNothing p) | ||
21 | |||
22 | |||
23 | flip : (a -> b -> c) -> (b -> a -> c) | ||
24 | flip f = | ||
25 | \x y -> f y x | ||
26 | |||
27 | |||
28 | diffDuration : Posix -> Posix -> Float | ||
29 | diffDuration t1 t2 = | ||
30 | let | ||
31 | m1 = | ||
32 | posixToMillis t1 | ||
33 | |||
34 | m2 = | ||
35 | posixToMillis t2 | ||
36 | in | ||
37 | toFloat (m2 - m1) / 1000 | ||
38 | |||
39 | |||
40 | wordCountWith : Array Word -> (WordStatus -> Bool) -> Int | ||
41 | wordCountWith words predicate = | ||
42 | words |> A.map .status |> A.filter predicate |> A.length | ||