Return-Path: X-Original-To: apmail-groovy-users-archive@minotaur.apache.org Delivered-To: apmail-groovy-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8A5351816B for ; Wed, 19 Aug 2015 09:53:17 +0000 (UTC) Received: (qmail 51674 invoked by uid 500); 19 Aug 2015 09:53:16 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 51641 invoked by uid 500); 19 Aug 2015 09:53:16 -0000 Mailing-List: contact users-help@groovy.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.incubator.apache.org Delivered-To: mailing list users@groovy.incubator.apache.org Received: (qmail 51631 invoked by uid 99); 19 Aug 2015 09:53:16 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Aug 2015 09:53:16 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id C9B601AA65B for ; Wed, 19 Aug 2015 09:53:15 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.9 X-Spam-Level: ** X-Spam-Status: No, score=2.9 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 98VAIhLDxXoV for ; Wed, 19 Aug 2015 09:53:05 +0000 (UTC) Received: from mail-wi0-f176.google.com (mail-wi0-f176.google.com [209.85.212.176]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id 36CA320488 for ; Wed, 19 Aug 2015 09:53:05 +0000 (UTC) Received: by wicne3 with SMTP id ne3so115891733wic.0 for ; Wed, 19 Aug 2015 02:53:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=6T6+xrIcSPSqtaOgRckQYUEqZ59Zk7ey4gHH1bacK74=; b=gxdjwe3Uxnhen22G9QKaN5UR/Ne/1cgNaPNYktx8b59pQuuWYEuLjdu3QnZ08+K6y2 ULMdHD6tw+Jelk8bo9MT4Obz52KFk07V40TZpm41JYpyqrC4VekYN/7FUpqRBreVDOUc cE2rYbgnfUdh07eXUHxE4AQ2ECBjhtvsq7a1ibhg54UQ+TlzkIiYgB4iGpMsnc8Imby8 SvZ0aj0Zb9NaQ4O9+2ceI/A7OfO6w/D8pdzPF1w3PHCMcvDMlTCNR9KbLkhH4kB7cf0n ylNRNAVQFluDaMW9boiJNMMblFGt7WHT6CKYJxeQY/I3+d84bL7h0Y0pGOneLQN96FFD 0tnQ== X-Received: by 10.194.57.19 with SMTP id e19mr23140136wjq.152.1439977983623; Wed, 19 Aug 2015 02:53:03 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.227.10 with HTTP; Wed, 19 Aug 2015 02:52:44 -0700 (PDT) From: Mehdi Elaoufir Date: Wed, 19 Aug 2015 10:52:44 +0100 Message-ID: Subject: Functional question : how to combine closures with same signature? To: users@groovy.incubator.apache.org Content-Type: multipart/alternative; boundary=047d7ba9782432c989051da700aa --047d7ba9782432c989051da700aa Content-Type: text/plain; charset=UTF-8 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 }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 --047d7ba9782432c989051da700aa Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi Groovy people,

I have busin= ess logic that is written in terms of small closure.

I want to be a= ble to combine as many closures as i want using logical operators &&= ;, ||..

All these closures have a similar functional signature :
(DomainObject,User) -&= gt; boolean


Say, for example these three closu= res :

def = isEnabled =3D {obj, user->user.enabled}
def canAccessObject=3D {obj, use= r->obj.owner?.id=3D=3Duser.id}
def isM= anager =3D {obj, user->user.hasRole('Manager')}
=

I want to be able to have a closure with the same signature :
<= br>def canProcessTransac= tion =3D isEnabled && canAccessObject || isManager
assert canProcessTrans= action(basket,userService.loggedInUser)

Is there = a Groovy way to do it?


Best regards
--047d7ba9782432c989051da700aa--