So, I managed to use Poly2 with foldRight to model a parametric map.
Here is an example to get an idea
object toRecord extends Poly2 { implicit def caseColumn[A, B] = at[Column[A], (Row, B)] { case (col, (row, acc)) => val field = doMyThingy(row, col) // "map" `col` to a recordField using `row` as parameter (row, field :: acc) } } def asRecord[L <: HList, O <: HList]( implicit folder: RightFolder[L, (Row, HNil.type), toRecord.type, (Row, O)] ): Stream[O] = { val resultSet: Stream[Row] = // computation to get result set resultSet.map { row => columns.foldRight((row, HNil))(toRecord)._2 } }
Thus, the “trick” here is to pass the parameter as the initial value of the bend and transfer it during the calculation.
Inside the calculation, we apply a transformation for each element, using row as a parameter (our “parametric mapping”), and then just add it to the battery.
When everything is ready, we get a tuple containing row and displayed HList : we can just discard the old one ( ._2 ), and we are good to go.
source share