mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-23 19:08:26 +00:00
Initial version.
Features: - Upload PDF files let them analyze - Manage meta data and items - See processing in webapp
This commit is contained in:
53
modules/webapp/src/main/elm/Util/List.elm
Normal file
53
modules/webapp/src/main/elm/Util/List.elm
Normal file
@ -0,0 +1,53 @@
|
||||
module Util.List exposing ( find
|
||||
, findIndexed
|
||||
, get
|
||||
, distinct
|
||||
, findNext
|
||||
, findPrev
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
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 pred list =
|
||||
findIndexed1 pred list 0
|
||||
|
||||
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)
|
||||
|
||||
distinct: List a -> List a
|
||||
distinct list =
|
||||
List.reverse <|
|
||||
List.foldl (\a -> \r -> if (List.member a r) then r 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 pred list =
|
||||
findIndexed pred list
|
||||
|> Maybe.map Tuple.second
|
||||
|> Maybe.map (\i -> i + 1)
|
||||
|> Maybe.andThen (get list)
|
Reference in New Issue
Block a user