mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-23 19:08:26 +00:00
Using elm-format for all files
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user