SHARE
TWEET

Untitled

a guest Sep 16th, 2019 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sealed trait GroupType
  2. case object BaseGroup extends GroupType
  3. case object UserGroup extends GroupType
  4.  
  5. sealed trait GroupObjectType
  6. case object UsersGroupObject extends GroupObjectType
  7. case object ClientGroupObject extends GroupObjectType
  8. case object ImagesGroupObject extends GroupObjectType
  9. case object ImageCollectionsGroupObject extends GroupObjectType
  10.  
  11. // enum GroupType {
  12. //   case BaseGroup
  13. //   case UserGroup
  14. // }
  15.  
  16. // enum GroupObjectType {
  17. //   case UsersGroupObject
  18. //   case ClientGroupObject
  19. //   case ImagesGroupObject
  20. //   case ImageCollectionsGroupObject
  21. // }
  22.  
  23. // import GroupType._
  24. // import GroupObjectType._
  25.  
  26. trait ValidGroupObjectCombination[GT <: GroupType, GOT <: GroupObjectType]
  27. given BaseUser as ValidGroupObjectCombination[BaseGroup.type, UsersGroupObject.type]
  28. given BaseClient as ValidGroupObjectCombination[BaseGroup.type, ClientGroupObject.type]
  29. given UserImages as ValidGroupObjectCombination[UserGroup.type, ImagesGroupObject.type]
  30.  
  31. def getSpecialGroups[GT <: GroupType, GOT <: GroupObjectType](
  32.     clientId:        String,
  33.     groupType:       GT,
  34.     groupObjectType: GOT
  35. ) given ValidGroupObjectCombination[GT, GOT]: List[String] = List("whatever")
  36.  
  37. // This compiles with the sealed trait version:
  38. println(getSpecialGroups("client1", BaseGroup, UsersGroupObject))
  39. // The explicitly given implicit is necessary for the enum version otherwise implicit not found error:
  40. // println(getSpecialGroups("client1", GroupType.BaseGroup(), GroupObjectType.UsersGroupObject()) given BaseUser)
  41. // This doesn't compile because there's no ValidGroupObjectCombination implicit exists for BaseGroup + ImageGroupObject
  42. // println(getSpecialGroups("client1", BaseGroup, ImagesGroupObject))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top