| 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/Array.elm | |
| parent | d2667e46fec8f15c29ffa80925d33b6931d8aa3b (diff) | |
...
Diffstat (limited to 'src/shared/elm/Shared/Util/Array.elm')
| -rw-r--r-- | src/shared/elm/Shared/Util/Array.elm | 54 | 
1 files changed, 54 insertions, 0 deletions
diff --git a/src/shared/elm/Shared/Util/Array.elm b/src/shared/elm/Shared/Util/Array.elm new file mode 100644 index 0000000..234b4c4 --- /dev/null +++ b/src/shared/elm/Shared/Util/Array.elm @@ -0,0 +1,54 @@ +module Shared.Util.Array exposing +   ( +      update, +      update_unsafe, +      filter_first, +      indexed_search +   ) + +import List +import Array + +update : ( +      Int -> +      ((Maybe t) -> (Maybe t)) -> +      (Array.Array t) -> +      (Array.Array t) +   ) +update index fun array = +   case (fun (Array.get index array)) of +      Nothing -> array +      (Just e) -> (Array.set index e array) + +update_unsafe : ( +      Int -> +      (t -> t) -> +      (Array.Array t) -> +      (Array.Array t) +   ) +update_unsafe index fun array = +   case (Array.get index array) of +      Nothing -> array +      (Just e) -> (Array.set index (fun e) array) + +filter_first : (t -> Bool) -> (Array.Array t) -> (Maybe t) +filter_first fun array = +   (Array.get 0 (Array.filter fun array)) + +indexed_search : (t -> Bool) -> (Array.Array t) -> (Maybe (Int, t)) +indexed_search fun array = +   (List.foldl +      (\v res -> +         ( +            case res of +               (Just e) -> res +               Nothing -> +                  let (index, value) = v in +                     if (fun value) +                     then (Just v) +                     else Nothing +         ) +      ) +      Nothing +      (Array.toIndexedList array) +   )  | 


