{-| Turn a list into a list of groups with a title
items = [ {cat = "Veggie", price = 7}
, {cat = "Veggie", price = 10}
, {cat = "Beef", price = 8}
, {cat = "Beef", price = 9}
]
cfg = {outerOrder = compare, innerOrder = compare, makeName = pipeComparison .cat compare}
makeGroups cfg items --> [{name = "Veggie", items = ""}] -- this will need to be run through the validate examples function
-}
makeGroups : GroupingConfig a -> List a -> Groups a
makeGroups {outerOrder, innerOrder, makeName} =
-- sort and make groups for outer
List.sortWith outerOrder
>> List.Extra.groupWhile (\a b -> (outerOrder a b) == EQ)
>> List.map (\(first, rest) -> {name = makeName first, items = first :: rest})
-- sort inner
>> List.map (\group -> {group | items = List.sortWith innerOrder group.items})
output
spec0 : Test.Test
spec0 =
Test.test "#makeGroups: \n\n items = [ {cat = \"Veggie\", price = 7}\n , {cat = \"Veggie\", price = 10}\n , {cat = \"Beef\", price = 8}\n , {cat = \"Beef\", price = 9}\n ]\n cfg = {outerOrder = compare, innerOrder = compare, makeName = pipeComparison .cat compare}\n makeGroups cfg items\n --> [{name = \"Veggie\", items = \"\"}] -- this will need to be run through the validate examples function" <|
\() ->
Expect.equal
(
items = [ {cat = "Veggie", price = 7}
, {cat = "Veggie", price = 10}
, {cat = "Beef", price = 8}
, {cat = "Beef", price = 9}
]
cfg = {outerOrder = compare, innerOrder = compare, makeName = pipeComparison .cat compare}
makeGroups cfg items
)
(
[{name = "Veggie", items = ""}] -- this will need to be run through the validate examples function
)
Reproduction example:
input:
output