0

I'm trying to implement a filter such as the one described in this gist (please see the last comment).

I want to wrap the salad bowl into a Fruits class, like this:

scala> class Fruits[L <: HList](val bowl: FruitBowl[L])

I then want to create multiple fruits in a list, like this:

scala> val fruits = List(new Fruits(new FruitBowl(Apple() :: Pear() :: HNil)), new Fruits(new FruitBowl(Pear() :: HNil)))

Then I just want to get the apple parts of each fruits, so I try to filter :

scala> fruits.map(_.bowl.getAll[Apple])

But then I get the following error :

<console>:16: error: could not find implicit value for parameter pf: shapeless.ops.hlist.Partition[_2,Apple]
   fruits.map(_.bowl.getAll[Apple])

But I though the Partition was supposed to be generic so I see no reason why it shouldn't be used...

I don't understand what's going on here with the implicits. Any idea of what's going wrong ?

MMacphail
  • 541
  • 3
  • 19
  • 2
    I think the issue is with the type of `fruits`, which loses precision – Gabriele Petronella Nov 07 '16 at 11:45
  • 1
    As @GabrielePetronella says, when you use `List` it widens the type of it's elements to find the common bound, so `fruits` has type `List[Fruits[HList]]`, all the information about the exact `L <: HList` types is lost and there's no implicit that could filter/partition an unknown `HList`. – laughedelic Nov 07 '16 at 13:33
  • 1
    Thank you both for your answer. I think I understood what you are saying and I'll be trying to work with a HList of HList to simulate the behaviour I want. – MMacphail Nov 07 '16 at 21:26
  • Actually that was not possible at compile-time since the lists are dynamycally sized :). So you're both right! – MMacphail Nov 14 '16 at 13:58

0 Answers0