| summaryrefslogtreecommitdiff | 
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2018-08-31 17:15:10 +0200 | 
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2018-08-31 17:15:10 +0200 | 
| commit | 89beca8b32b3fcb43abcb6167709caad1ffe94ee (patch) | |
| tree | 02cfdd6dd5b81d5a8a48985b86fd51a6c1210625 /src/shared/elm | |
| parent | ef01f7826ac3fdf8434d9e8af2eef86638b058e9 (diff) | |
Adds a directory for shared code.
Diffstat (limited to 'src/shared/elm')
| -rw-r--r-- | src/shared/elm/Util/Array.elm | 34 | ||||
| -rw-r--r-- | src/shared/elm/Util/Html.elm | 6 | ||||
| -rw-r--r-- | src/shared/elm/Util/List.elm | 36 | 
3 files changed, 76 insertions, 0 deletions
| diff --git a/src/shared/elm/Util/Array.elm b/src/shared/elm/Util/Array.elm new file mode 100644 index 0000000..9e57c18 --- /dev/null +++ b/src/shared/elm/Util/Array.elm @@ -0,0 +1,34 @@ +module Util.Array exposing +   ( +      update, +      update_unsafe, +      filter_first +   ) + +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)) diff --git a/src/shared/elm/Util/Html.elm b/src/shared/elm/Util/Html.elm new file mode 100644 index 0000000..42eadba --- /dev/null +++ b/src/shared/elm/Util/Html.elm @@ -0,0 +1,6 @@ +module Util.Html exposing (nothing) + +import Html + +nothing : (Html.Html a) +nothing = (Html.text "") diff --git a/src/shared/elm/Util/List.elm b/src/shared/elm/Util/List.elm new file mode 100644 index 0000000..1f914b1 --- /dev/null +++ b/src/shared/elm/Util/List.elm @@ -0,0 +1,36 @@ +module Util.List exposing (..) + +import List + +pop : List a -> (Maybe (a, List a)) +pop l = +   case +      ((List.head l), (List.tail l)) +   of +      (Nothing, _) -> Nothing +      (_ , Nothing) -> Nothing +      ((Just head), (Just tail)) -> (Just (head, tail)) + +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 +            ) +         ) + | 


