collections - Groovy subcollection -
what groovy way collection items without items in subcollection. example:
collection: [1,2,3,4,5,6]
subcollection: [1,5,6]
the result should be: [2,3,4]
edit: looks i'm doing wrong. part of code:
def report = report.get(params.report.id) def user = user.get(params.user.id) list<user> availableusers = [] availableusers = user.findallbycompany(company)) list<user> addedusers = [] addedusers = (list<user>) session["addedusers"] ?: [] addedusers << user session["addedusers"] = null session["addedusers"] = addedusers availableusers = availableusers - addedusers
this code removing last user in addedusers list.
availableusers: [john, jack, jim]
addedusers: [john, jack]
availableusers - addedusers: [john, jim]
every time last item in addedusers gets removed. i'm guessing i'm missing obvious cant find it.
did try obvious:
result = [ 1, 2, 3, 4, 5, 6 ] - [ 1, 5, 6 ]
because works...
edit
storing domain object in session result in object being different between hibernate transactions, better store id in session , users fresh each time (or write functionality domain if needs persisting), like:
addedusers = session["addedusers"].collect { user.get( it.id ) } ?: []