groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mehdi Elaoufir <melaou...@gmail.com>
Subject Functional question : how to combine closures with same signature?
Date Wed, 19 Aug 2015 09:52:44 GMT
Hi Groovy people,

I have business logic that is written in terms of small closure.

I want to be able to combine as many closures as i want using logical
operators &&, ||..

All these closures have a similar functional signature :
*(DomainObject,User) -> boolean*

Say, for example these three closures :


*def isEnabled = {obj, user->user.enabled}*

*def canAccessObject= {obj, user->obj.owner?.id==user.id
<http://user.id>}def isManager = {obj, user->user.hasRole('Manager')}*

I want to be able to have a closure with the same signature :


*def canProcessTransaction = isEnabled && canAccessObject || isManager*
*assert canProcessTransaction(basket,userService.loggedInUser) *

Is there a Groovy way to do it?


Best regards

Mime
View raw message