Last active
November 23, 2017 10:04
-
-
Save yakticus/4622facd96ac6bdf17cf to your computer and use it in GitHub Desktop.
Hlist filter attempt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import shapeless.HNil | |
| object Example { | |
| trait Fruit | |
| case class Apple() | |
| case class Pear() | |
| // there could be more types of fruit defined elsewhere | |
| class FruitBowl { | |
| private[this] var fruits = HNil | |
| def add[F <: Fruit](fruit: F): Unit = { | |
| fruits = fruit :: fruits // <-- Error:(15, 22) type mismatch; | |
| // found : shapeless.::[F,shapeless.HNil] | |
| // required: shapeless.HNil.type | |
| } | |
| def getAll[F <: Fruit] = fruits.filter[F] // <-- Error:(18, 43) could not find implicit value for parameter partition: | |
| // shapeless.ops.hlist.Partition[shapeless.HNil.type,F] | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This one works (contributed by @milessabin):
Heres its use on the REPL: