You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Again, this is a small syntax change which only makes the code a bit more
50
+
Again, this is a small syntax change which makes the code a little more
49
51
readable.
50
52
51
53
52
54
## Elvis assignment operator
53
55
54
-
The elvis assigment operator `?=` allows the assignment of a value only if it was
55
-
not previouvsly assigned (or it evaluets to `null`). Consider the following example:
56
+
The elvis assignment operator `?=` allows the assignment of a value only if it was not
57
+
previously assigned (or if it evaluates to `null`). Consider the following example:
56
58
57
59
```
58
60
def opts = [foo: 1]
@@ -64,8 +66,8 @@ assert opts.foo == 1
64
66
assert opts.bar == 20
65
67
```
66
68
67
-
In this snippet the assignment `opts.foo ?= 10`is ignored because the dictionary `opts` already
68
-
contains a value for the `foo` attribute, while the following is assigned as expected.
69
+
In this snippet, the assignment `opts.foo ?= 10`would be ignored because the dictionary `opts` already
70
+
contains a value for the `foo` attribute, while it is now assigned as expected.
69
71
70
72
In other words this is a shortcut for the following idiom:
71
73
@@ -75,20 +77,20 @@ if( some_variable != null ) {
75
77
}
76
78
```
77
79
78
-
### Java style lambda expression
80
+
### Java style lambda expressions
79
81
80
-
Groovy 3 supports the syntax for Java lambda expression. If you don't know what is a Java lamda expression
81
-
don't worry, it's a concept very similar to a Groovy closure, thought with slight differences
82
-
both in the syntax and the semantic (i na few words a Groovy closure can modify a variable in the outside scope,
83
-
while a Java lamda cannot).
82
+
Groovy 3 supports the syntax for Java lambda expression. If you don't know what a Java lambda expression is
83
+
don't worry; it's a concept very similar to a Groovy closure, though with slight differences
84
+
both in the syntax and the semantic. In a few words, a Groovy closure can modify a variable in the outside scope,
85
+
while a Java lambda cannot.
84
86
85
-
In terms of syntax a Groovy closure is defined as:
87
+
In terms of syntax, a Groovy closure is defined as:
86
88
87
89
```
88
90
{ it -> SOME_EXPRESSION_HERE }
89
91
```
90
92
91
-
While Java lamba looks like:
93
+
While Java lambda expression looks like:
92
94
93
95
```
94
96
it -> { SOME_EXPRESSION_HERE }
@@ -100,11 +102,11 @@ which can be simplified to the following form when the expression is a single st
100
102
it -> SOME_EXPRESSION_HERE
101
103
```
102
104
103
-
The good news is that the two syntax are interoperable in many cases and we can use the *lamda*
104
-
syntax to get rid-off of the curly bracket parentheses used by the Groovy notation and make our Nextflow
105
+
The good news is that the two syntaxes are interoperable in many cases and we can use the *lambda*
106
+
syntax to get rid-off of the curly bracket parentheses used by the Groovy notation to make our Nextflow
105
107
script more readable.
106
108
107
-
For example the following Nextlow idiom:
109
+
For example, the following Nextflow idiom:
108
110
109
111
```
110
112
Channel
@@ -113,7 +115,7 @@ Channel
113
115
.view { "the value is $it" }
114
116
```
115
117
116
-
Can be rewritting using the labda syntax as:
118
+
Can be rewritten using the lambda syntax as:
117
119
118
120
```
119
121
Channel
@@ -122,7 +124,7 @@ Channel
122
124
.view( it -> "the value is $it" )
123
125
```
124
126
125
-
Which is a bit more consistent. Note however that the `it ->` implicit argument is now mandatory (while using the closure syntax it could be omitted) and when the operator argument is not *single* value, the lambda requires the
127
+
It is a bit more consistent. Note however that the `it ->` implicit argument is now mandatory (while when using the closure syntax it could be omitted). Also, when the operator argument is not *single* value, the lambda requires the
126
128
round parentheses to define the argument e.g.
127
129
128
130
```
@@ -133,13 +135,13 @@ Channel
133
135
```
134
136
135
137
136
-
### Fully support Java streams API
138
+
### Full support for Java streams API
137
139
138
-
Java since version 8 provide a [stream library](https://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/) that is very powerful and implements some concepts and operators similar to Nextflow channels.
140
+
Since version 8, Java provides a [stream library](https://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/) that is very powerful and implements some concepts and operators similar to Nextflow channels.
139
141
140
-
The main differences between the two is the Nextflow channels and the corresponding operators are *non-blocking*
142
+
The main differences between the two are that Nextflow channels and the corresponding operators are *non-blocking*
141
143
i.e. their evaluation is performed asynchronously without blocking your program execution, while Java streams are
142
-
executed in a synchronus manner (at least by default).
144
+
executed in a synchronous manner (at least by default).
143
145
144
146
A Java stream looks like the following:
145
147
@@ -163,9 +165,9 @@ methods are Java stream operator not the
163
165
164
166
### Java style method reference
165
167
166
-
The new runtime allows also the use of the `::` operator to reference an object method.
167
-
This can be useful to pass a method as an argument to a Nextflow operator in a similar manner
168
-
how it was already possible using a closure. For example:
168
+
The new runtime also allows for the use of the `::` operator to reference an object method.
169
+
This can be useful to pass a method as an argument to a Nextflow operator in a similar
170
+
manner to how it was already possible using a closure. For example:
169
171
170
172
```
171
173
Channel
@@ -188,13 +190,12 @@ to each element emitted by the channel.
188
190
189
191
### Conclusion
190
192
191
-
The new Groovy runtime brings a lot syntax sugar for Nextflow pipelines and allow the use of modern Java
192
-
runtime which deliver better performances and resources usage.
193
+
The new Groovy runtime brings a lot of syntax sugar for Nextflow pipelines and allows the use of modern Java
194
+
runtime which delivers better performance and resource usage.
193
195
194
-
The ones listed above are only some of them which may be usefull to everyday Nextflow developers.
195
-
If you are curious to learn more about all the changes in the new Groovy parser you can find a
196
+
The ones listed above are only a small selection which may be useful to everyday Nextflow developers.
197
+
If you are curious to learn more about all the changes in the new Groovy parser you can find more details in
0 commit comments