| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2020-05-10 18:08:26 +0200 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2020-05-10 18:08:26 +0200 | 
| commit | fc09d979e4c753377131684b1100c250e89765ea (patch) | |
| tree | a79689b720794b4a5503ac63ff4c84dfd04e6f41 /src/shared/elm/Shared/Util/List.elm | |
| parent | d2667e46fec8f15c29ffa80925d33b6931d8aa3b (diff) | |
...
Diffstat (limited to 'src/shared/elm/Shared/Util/List.elm')
| -rw-r--r-- | src/shared/elm/Shared/Util/List.elm | 50 | 
1 files changed, 50 insertions, 0 deletions
| diff --git a/src/shared/elm/Shared/Util/List.elm b/src/shared/elm/Shared/Util/List.elm new file mode 100644 index 0000000..6a22a5a --- /dev/null +++ b/src/shared/elm/Shared/Util/List.elm @@ -0,0 +1,50 @@ +module Shared.Util.List exposing (..) + +import Set + +import List + +pop : List a -> (Maybe (a, List a)) +pop l = +   case l of +      (head :: tail) -> (Just (head, tail)) +      [] -> Nothing + +get_first : (a -> Bool) -> (List a) -> (Maybe a) +get_first fun list = +   (List.head (List.filter fun list)) + +product_map : (a -> b -> c) -> (List a) -> (List b) -> (List c) +product_map product_fun list_a list_b = +   (product_map_rec (product_fun) list_a list_b []) + +product_map_rec : (a -> b -> c) -> (List a) -> (List b) -> (List c) -> (List c) +product_map_rec product_fun list_a list_b result = +   case (pop list_a) of +      Nothing -> result +      (Just (head, tail)) -> +         (product_map_rec +            (product_fun) +            tail +            list_b +            (List.append +               (List.map (product_fun head) list_b) +               result +            ) +         ) + +duplicates : (List comparable) -> (Set.Set comparable) +duplicates list = +   let +      (encountered, final_result) = +         (List.foldl +            (\elem (met, result) -> +               if (Set.member elem met) +               then (met, (Set.insert elem result)) +               else ((Set.insert elem met), result) +            ) +            ((Set.empty), (Set.empty)) +            list +         ) +   in +      final_result | 


