Using elm-format for all files

This commit is contained in:
Eike Kettner
2019-12-29 21:55:12 +01:00
parent 546f1a6ee3
commit 2001cca88b
84 changed files with 7668 additions and 5079 deletions

View File

@ -1,51 +1,80 @@
module Util.List exposing ( find
, findIndexed
, get
, distinct
, findNext
, findPrev
)
module Util.List exposing
( distinct
, find
, findIndexed
, findNext
, findPrev
, get
)
get: List a -> Int -> Maybe a
get : List a -> Int -> Maybe a
get list index =
if index < 0 then Nothing
else case list of
[] ->
Nothing
x :: xs ->
if index == 0
then Just x
else get xs (index - 1)
if index < 0 then
Nothing
find: (a -> Bool) -> List a -> Maybe a
else
case list of
[] ->
Nothing
x :: xs ->
if index == 0 then
Just x
else
get xs (index - 1)
find : (a -> Bool) -> List a -> Maybe a
find pred list =
findIndexed pred list |> Maybe.map Tuple.first
findIndexed: (a -> Bool) -> List a -> Maybe (a, Int)
findIndexed : (a -> Bool) -> List a -> Maybe ( a, Int )
findIndexed pred list =
findIndexed1 pred list 0
findIndexed1: (a -> Bool) -> List a -> Int -> Maybe (a, Int)
findIndexed1 : (a -> Bool) -> List a -> Int -> Maybe ( a, Int )
findIndexed1 pred list index =
case list of
[] -> Nothing
x :: xs ->
if pred x then Just (x, index)
else findIndexed1 pred xs (index + 1)
[] ->
Nothing
distinct: List a -> List a
x :: xs ->
if pred x then
Just ( x, index )
else
findIndexed1 pred xs (index + 1)
distinct : List a -> List a
distinct list =
List.reverse <|
List.foldl (\a -> \r -> if (List.member a r) then r else a :: r) [] list
List.foldl
(\a ->
\r ->
if List.member a r then
r
findPrev: (a -> Bool) -> List a -> Maybe a
else
a :: r
)
[]
list
findPrev : (a -> Bool) -> List a -> Maybe a
findPrev pred list =
findIndexed pred list
|> Maybe.map Tuple.second
|> Maybe.map (\i -> i - 1)
|> Maybe.andThen (get list)
findNext: (a -> Bool) -> List a -> Maybe a
findNext : (a -> Bool) -> List a -> Maybe a
findNext pred list =
findIndexed pred list
|> Maybe.map Tuple.second