groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Sun (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (GROOVY-8998) [GEP]Concatenative Method Calls
Date Wed, 20 Feb 2019 09:11:00 GMT

     [ https://issues.apache.org/jira/browse/GROOVY-8998?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Daniel Sun updated GROOVY-8998:
-------------------------------
    Description: 
h1.  *DRAFT*
{code:java}
// lots of temp variable declarations and assignments
def ar = a()
def br = b(3, ar)
def  r = c(br, 2)

// inline version of the above code, i.e. nested method calls
def r =
	c(
		b(
			3,
			a()
		), 
		2
	)
{code}
{code:java}
// leverage the power of DGM `with` to transform nested method calls to method call chain
def r =
	a().with {
	   b(3, it)
	}. with {
	   c(it, 2)
	}
{code}
{code:java}
//  Introduce a new syntax to transform the above method call chain to concatenative method
calls
//  `_`  represents the result of previous part
//  `|>` is like a big arrow representing the direction of data flow
// if the target is a variable, `|>` means assignment/declaration
a()  |>  b(3, _)  |>  c(_, 2)  |> (def r)
{code}

h2. More examples
{code:java}
// `|>` has just a bit higher precedence than assignments, e.g. `=`, `+=`, `*=`, etc.
6 / a()  |>  b(3, _)  + 9 |>  c(_, 2) * 5  |> (def r)
// the above code is equal to
def r =
	c(
		b(
			3,
			6 / a()
		) + 9, 
		2
	) * 5
{code}
h2. discussion in the dev mailing list
 [http://groovy.329449.n5.nabble.com/GEP-Concatenative-Method-Calls-tt5747708.html]

  was:
 *DRAFT*
{code:java}
// lots of temp variable declarations and assignments
def ar = a()
def br = b(3, ar)
def  r = c(br, 2)

// inline version of the above code, i.e. nested method calls
def r =
	c(
		b(
			3,
			a()
		), 
		2
	)
{code}
{code:java}
// leverage the power of DGM `with` to transform nested method calls to method call chain
def r =
	a().with {
	   b(3, it)
	}. with {
	   c(it, 2)
	}
{code}
{code:java}
//  Introduce a new syntax to transform the above method call chain to concatenative method
calls
//  `_`  represents the result of previous part
//  `|>` is like a big arrow representing the direction of data flow
// if the target is a variable, `|>` means assignment/declaration
a()  |>  b(3, _)  |>  c(_, 2)  |> (def r)
{code}
{code:java}
// `|>` has just a bit higher precedence than assignments, e.g. `=`, `+=`, `*=`, etc.
6 / a()  |>  b(3, _)  + 9 |>  c(_, 2) * 5  |> (def r)
// the above code is equal to
def r =
	c(
		b(
			3,
			6 / a()
		) + 9, 
		2
	) * 5
{code}
discussion in the dev mailing list:
 [http://groovy.329449.n5.nabble.com/GEP-Concatenative-Method-Calls-tt5747708.html]


> [GEP]Concatenative Method Calls
> -------------------------------
>
>                 Key: GROOVY-8998
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8998
>             Project: Groovy
>          Issue Type: New Feature
>            Reporter: Daniel Sun
>            Assignee: Daniel Sun
>            Priority: Major
>
> h1.  *DRAFT*
> {code:java}
> // lots of temp variable declarations and assignments
> def ar = a()
> def br = b(3, ar)
> def  r = c(br, 2)
> // inline version of the above code, i.e. nested method calls
> def r =
> 	c(
> 		b(
> 			3,
> 			a()
> 		), 
> 		2
> 	)
> {code}
> {code:java}
> // leverage the power of DGM `with` to transform nested method calls to method call chain
> def r =
> 	a().with {
> 	   b(3, it)
> 	}. with {
> 	   c(it, 2)
> 	}
> {code}
> {code:java}
> //  Introduce a new syntax to transform the above method call chain to concatenative
method calls
> //  `_`  represents the result of previous part
> //  `|>` is like a big arrow representing the direction of data flow
> // if the target is a variable, `|>` means assignment/declaration
> a()  |>  b(3, _)  |>  c(_, 2)  |> (def r)
> {code}
> h2. More examples
> {code:java}
> // `|>` has just a bit higher precedence than assignments, e.g. `=`, `+=`, `*=`, etc.
> 6 / a()  |>  b(3, _)  + 9 |>  c(_, 2) * 5  |> (def r)
> // the above code is equal to
> def r =
> 	c(
> 		b(
> 			3,
> 			6 / a()
> 		) + 9, 
> 		2
> 	) * 5
> {code}
> h2. discussion in the dev mailing list
>  [http://groovy.329449.n5.nabble.com/GEP-Concatenative-Method-Calls-tt5747708.html]



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message