From c414c2b9127921d77237d0ad018b87ad044915e8 Mon Sep 17 00:00:00 2001 From: nsensfel Date: Thu, 13 Sep 2018 18:30:08 +0200 Subject: ... --- src/Util/List.elm | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/Util/List.elm (limited to 'src/Util/List.elm') diff --git a/src/Util/List.elm b/src/Util/List.elm new file mode 100644 index 0000000..1f914b1 --- /dev/null +++ b/src/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 + ) + ) + -- cgit v1.2.3-70-g09d2