need a curry example in Xtend lang

77 views
Skip to first unread message

Manav Brar

unread,
Sep 9, 2016, 2:09:58 PM9/9/16
to Xtend Programming Language
seems like Xtend has some curry capability but not documented

Artur Biesiadowski

unread,
Sep 9, 2016, 4:37:20 PM9/9/16
to Xtend Programming Language
You can cheat a bit with lambdas. Unfortunately, doing it for 3+ argument functions seems to require bit more typing.


class Test {
   
static def void function(int x, String y) {
        println
(x + " " + y)
   
}
}

class CurryExample {
   
def static void main(String[] args) {
        val f1
= [Test.function(500,it)]
       
        f1
.apply("Str")
        f1
.apply("Second String")
   
}
}

Manav Brar

unread,
Sep 9, 2016, 5:31:34 PM9/9/16
to Xtend Programming Language
does everything have to be static for curry to work? As I have to use all this with Spring containers

Artur Biesiadowski

unread,
Sep 10, 2016, 4:17:48 AM9/10/16
to Xtend Programming Language
I assume that by 'currying' you mean partial application.

Is it at all defined what it means for methods? This concept is from functional languages, for pure/static functions. But you can do something like


@Data
class Test {
   
int v;

   
def void function(int x, String y) {

        println
(v + " " + x + " " + y)

   
}
}

class CurryExample {
   
def static void main(String[] args) {

       
        val t
= new Test(6)
       
        val f1
= [int a,String b|t.function(a,b)]
       
        val f2
= [f1.apply(500,it)]
       
        f1
.apply(100,"Two params with partially applied this")
       
        f2
.apply("Str")
        f2
.apply("Second String")
   
}
}


As I said - it is not pretty with 2+ params, as xtend currently is not able to infer the types in such case.

Maybe you can give us exact problem you are trying to achieve? There might be smarter solutions with active annotations for example.

Manav Brar

unread,
Sep 13, 2016, 1:49:34 PM9/13/16
to Xtend Programming Language
Several use cases come to mind
  1. Write automation for API's and live in a testNg world which provides an easy way to scaling up the tests on a single VM. 
  2. Issues I am running into are web services return a response at an inconsistent time so need a way to coordinate test that is running multiple threads. All of my assignments have val so everything is all final. 
Reply all
Reply to author
Forward
0 new messages