aboutsummaryrefslogtreecommitdiff
path: root/src/client/Utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/Utils')
-rw-r--r--src/client/Utils/List.elm19
-rw-r--r--src/client/Utils/Maybe.elm34
2 files changed, 19 insertions, 34 deletions
diff --git a/src/client/Utils/List.elm b/src/client/Utils/List.elm
index cc57d9f..8e26e85 100644
--- a/src/client/Utils/List.elm
+++ b/src/client/Utils/List.elm
@@ -1,9 +1,11 @@
module Utils.List exposing
( groupBy
, mean
+ , links
)
import Dict
+import Maybe.Extra as Maybe
groupBy : (a -> comparable) -> List a -> List (comparable, List a)
groupBy f xs =
@@ -15,3 +17,20 @@ groupBy f xs =
mean : List Int -> Int
mean xs = (List.sum xs) // (List.length xs)
+
+links : List a -> List (a, a)
+links xs =
+ let reversed = List.reverse xs
+ in List.foldr
+ (\x acc ->
+ case Maybe.map Tuple.first (List.head acc) of
+ Just y ->
+ (x, y) :: acc
+ _ ->
+ acc
+ )
+ (case reversed of
+ x :: y :: _ -> [(y, x)]
+ _ -> []
+ )
+ (List.reverse << List.drop 2 <| reversed)
diff --git a/src/client/Utils/Maybe.elm b/src/client/Utils/Maybe.elm
deleted file mode 100644
index 46456e1..0000000
--- a/src/client/Utils/Maybe.elm
+++ /dev/null
@@ -1,34 +0,0 @@
-module Utils.Maybe exposing
- ( isJust
- , cat
- , toList
- , orElse
- )
-
-isJust : Maybe a -> Bool
-isJust maybe =
- case maybe of
- Just _ -> True
- Nothing -> False
-
-cat : List (Maybe a) -> List a
-cat =
- List.foldr
- (\mb xs ->
- case mb of
- Just x -> x :: xs
- Nothing -> xs
- )
- []
-
-toList : Maybe a -> List a
-toList mb =
- case mb of
- Just a -> [a]
- Nothing -> []
-
-orElse : Maybe a -> Maybe a -> Maybe a
-orElse mb1 mb2 =
- case mb1 of
- Just x -> Just x
- Nothing -> mb2