type alias Bag a = List (a, Int)
I am trying to create functions that work with this type alias but I can't figure out how to return a Bag from a function.. Like in the following function I am hoping to insert a new item into an existing bag (could be empty, which is the only case I am trying to get working at the moment).
insert : a -> Bag a -> Bag a
insert b c = case c of
[] -> Bag a : [(b, 1)]
--this case below is what I'm hoping could work out..cant really check without getting the first case to work---
x::xs -> if Tuple.first x == b
then Bag a : [(b, (Tuple.second x) + 1)] ++ xs
else [x] ++ insert b xs
How can I initialize a new Bag without using this multi-line method below?
testBag : Bag Int
testBag = [(5,1),(2,1)]
PS very new to Elm and struggling to find resources that can help me shift from an imperative mindset..