This is an automated email from the ASF dual-hosted git repository. paulk pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/groovy.git
commit f8fcd96a99fd7dbada9f250d0a45dbd0d2e51c0e Author: Otto Vayrynen <[email protected]> AuthorDate: Wed Apr 7 18:57:51 2021 +0300 GROOVY-9649: Added documentation for left-open and full-open ranges --- src/spec/doc/_working-with-collections.adoc | 6 ++++++ src/spec/doc/core-operators.adoc | 6 ++++-- src/spec/doc/core-semantics.adoc | 2 +- src/spec/test/OperatorsTest.groovy | 8 ++++---- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/spec/doc/_working-with-collections.adoc b/src/spec/doc/_working-with-collections.adoc index 9faf413..4e93da0 100644 --- a/src/spec/doc/_working-with-collections.adoc +++ b/src/spec/doc/_working-with-collections.adoc @@ -341,6 +341,12 @@ contains the from and to value). Ranges defined with the `..<` notation are half-open, they include the first value but not the last value. +Ranges defined with the `<..` notation are also half-open, they include the +last value but not the first value. + +Ranges defined with the `<..<` notation are full-open, they do not include the +first value nor the last value. + [source,groovy] ---------------------------------------------------------------------------- include::../test/gdk/WorkingWithCollectionsTest.groovy[tags=intrange,indent=0] diff --git a/src/spec/doc/core-operators.adoc b/src/spec/doc/core-operators.adoc index e9a5f04..78726bf 100644 --- a/src/spec/doc/core-operators.adoc +++ b/src/spec/doc/core-operators.adoc @@ -705,8 +705,10 @@ include::../test/OperatorsTest.groovy[tags=intrange,indent=0] <1> a simple range of integers, stored into a local variable <2> an `IntRange`, with inclusive bounds <3> an `IntRange`, with exclusive upper bound -<4> a `groovy.lang.Range` implements the `List` interface -<5> meaning that you can call the `size` method on it +<4> an `IntRange`, with exclusive lower bound +<5> an `IntRange`, with exclusive lower and upper bounds +<6> a `groovy.lang.Range` implements the `List` interface +<7> meaning that you can call the `size` method on it Ranges implementation is lightweight, meaning that only the lower and upper bounds are stored. You can create a range from any `Comparable` object that has `next()` and `previous()` methods to determine the next / previous item in the range. diff --git a/src/spec/doc/core-semantics.adoc b/src/spec/doc/core-semantics.adoc index a86bf02..45e7e42 100644 --- a/src/spec/doc/core-semantics.adoc +++ b/src/spec/doc/core-semantics.adoc @@ -1545,7 +1545,7 @@ Groovy provides a syntax for various type literals. There are three native colle * lists, using the `[]` literal * maps, using the `[:]` literal -* ranges, using `from..to` (inclusive) and `from..<to` (exclusive) +* ranges, using `from..to` (inclusive), `from..<to` (right exclusive),`from<..to` (left exclusive) and `from<..<to` (full exclusive) The inferred type of a literal depends on the elements of the literal, as illustrated in the following table: diff --git a/src/spec/test/OperatorsTest.groovy b/src/spec/test/OperatorsTest.groovy index 3f9746c..94f0d29 100644 --- a/src/spec/test/OperatorsTest.groovy +++ b/src/spec/test/OperatorsTest.groovy @@ -543,10 +543,10 @@ assert function(*args,5,6) == 26 def range = 0..5 // <1> assert (0..5).collect() == [0, 1, 2, 3, 4, 5] // <2> assert (0..<5).collect() == [0, 1, 2, 3, 4] // <3> - assert (0<..5).collect() == [1, 2, 3, 4, 5] - assert (0<..<5).collect() == [1, 2, 3, 4] - assert (0..5) instanceof List // <4> - assert (0..5).size() == 6 // <5> + assert (0<..5).collect() == [1, 2, 3, 4, 5] // <4> + assert (0<..<5).collect() == [1, 2, 3, 4] // <5> + assert (0..5) instanceof List // <6> + assert (0..5).size() == 6 // <7> // end::intrange[] ''' assertScript '''
