I have a Set, and I want to implicitly add another value to the end of that Set when it is called.
For example, I need something like this to work:
implicit def addToSet(set: Set[Int]) = set + 4
val s = Set(1, 2, 3)
println(s) // Set(1, 2, 3, 4)
Use case:
I am building a website (using PlayFramework), and I have about 20-30 Sets of roles which correspond to different pieces of functionality. For each page, only certain roles can access certain features, so I have a bit of functionality each time I need to check role privileges (in pseudocode: if(role.canAccess(/*name of page*/))) which checks if the role that the user is logged in as is contained in the Set which corresponds to /*name of page*/.
I am now creating a super user which has access to every piece of functionality on every page, so that user's "role" needs to be in every Set. I don't want to have to do this by manually adding this role to every Set because I want this to be scalable and easily maintainable, so I was hoping for a solution which just adds this new super role to each Set automatically behind the scenes.
I'm open to non-implicit answers too, as long as they don't modify the original Sets I already have.