[ 
https://issues.apache.org/jira/browse/GROOVY-12220?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18105165#comment-18105165
 ] 

Paul King commented on GROOVY-12220:
------------------------------------

What you propose is fine if you want that particular syntax. There are a number 
of existing ways to do something similar:
{code:groovy}
x = { it ** 2 + it }
assert 4.with(x).with{ it/2 }.with(Foo.&foo) == 13

def pipeline = x >> { it/2 } >> Foo.&foo
assert pipeline(4) == 13

assert 13 == (x >> { it/2 } >> Foo.&foo)(4)

assert 13 == Foo.&foo << { it/2 } << x << 4
{code}

> Pipeline Operator Support (possibly for groovy 6)
> -------------------------------------------------
>
>                 Key: GROOVY-12220
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12220
>             Project: Groovy
>          Issue Type: New Feature
>            Reporter: Aleks Tamarkin
>            Priority: Major
>
> Suggestion to add a functional pipline operator to Groovy
> Groovy already prioritized writing code left to right with awesome 
> improvements over java like `someString.toURL()` instead of `new 
> URL(someString)`
> A pipleine operator could make this even more universal
> Example implementation using xor `^`
> {code:java}
> class PipelineOperator {
>   static xor(Object self, Closure c) {
>     c(self)
>   }
> }
> class Foo { static foo(v) { v + 3 } }
> Closure example = { 
>    def x = { it ** 2 + it }
>    4 ^ x ^ { it / 2 } ^ (Foo.&foo)
> }
> use(PipelineOperator) {
>   example() // 4 -> 4 * 4 + 4 = 20 -> 20 / 2 = 10 -> 10 + 3 = 13
> }{code}
> Example in F# 
> [https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/functions/#pipelines]
> Thanks in advance for taking a look
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to