I have a table Bill containing Bills with 0...n relationships to Material and Activity (line items on the bill).My SQL query is essentially bill left join material left join activity.  I have the following insanely tangled code to transform the results into a Map[Bill, (HashSet[Activity], HashSet[Material])].What's wrong with this code?  Is this whole approach wrong?  I'm new to Scala and the functional world, but it doesn't seem like this could be the right way. SQL(                      |SELECT            | b.id, b.dateDue            | ,a.id as activityId, a.notes, a.startTime, a.endTime            | ,m.id as materialId, m.cost, m.description, m.storageLocation            |FROM Bill b            |LEFT JOIN Activity a ON a.bill_id = b.id            |LEFT JOIN Material m ON m.bill_id = b.id            |WHERE b.id = {id}          .stripMargin)        .on(id -> id)        .as(betterParser *)        .groupBy( x=> (x._1, x._2))        .map( q => q._1 ->                 q._2.foldLeft( (HashSet[Activity](), HashSet[Material]()) )                 ( (acc, item) =>  (acc._1 + item._3, acc._2 + item._4)))betterParser transforms each row from the query into a (Long, DateTime, Activity, Material) where the  (Long, DateTime) portion are overall bill poperties. val betterParser = {    billParser ~ activityParser ~ materialParser map {      case bill ~ activity ~ material =>       (bill._1, bill._2, activity, material)   } }
Neatly Transforming Anorm ResultSet Into Map[Parent , (Set[Child1], Set[Child2]))]
sql;functional programming;scala