Suppose I have some tabular data
| John | James | |
|---|---|---|
| January | 3 | 5 |
| February | 2 | 8 |
where the rows have type Month and the columns have type Name.
I could group the data first by Month and then by Name and use type MonthlyData = Map Month (Map Name Int).
Or I could group them first by Name and then by Month and some something like type MonthlyData' = Map Name (Map Month Int).
Or I could group them by Name and Month and use type MonthlyData'' = Map (Month, Name) Int.
I would like to be able to access both rows, providing a Month, and columns, providing a Name.
Is there in the ecosystem a data structure optimised for that?
If not, would it make sense to have something like
data MonthlyData''' = MonthlyData'''
{ groupByName :: Map Name (Map Month Int)
, groupByMonth :: Map Month (Map Name Int)
}
-- uses groupByName
lookupByName :: Name -> MonthlyData''' -> Maybe (Map Month Int)
-- uses groupByMonth
lookupByMonth :: Month -> MonthlyData''' -> Maybe (Map Name Int)
insert :: Name -> Month -> MonthlyData''' -> MonthlyData'''
update :: Name -> Month -> Int -> MonthlyData''' -> MonthlyData'''
where the constructor MonthlyData''' is not exposed and insert and update modify both groupByMonth and groupByName?
