XUtils

groovy-extra-list-behaviour

Adds extra methods to Lists via the extension system


Groovy Extra List Behaviour

Build Status

About »
Using this library »
New methods available »
Releases »
Thanks »

Using this library

You can include this library in your project in a number of ways, detailed below.

Via Grape

e.g. for use in Groovy scripts (including in the GroovyConsole)

@Grab('com.dnahodil.groovy.extensions:groovy-extra-list-behaviour')

In Grails

Grails version > 2.4.4 is required for this to work automatically.

compile('com.dnahodil.groovy.extensions:groovy-extra-list-behaviour:x.y.z')

For earlier versions of Grails I wrote a blog post describing Adding Groovy extension modules to a Grails application. You will either need to download the jar to include in your Grails app, or build it yourself using this repository.

Via Gradle

compile 'com.dnahodil.groovy.extensions:groovy-extra-list-behaviour:x.y.z'

Via Maven

<dependency>
	<groupId>com.dnahodil.groovy.extensions</groupId>
	<artifactId>groovy-extra-list-behaviour</artifactId>
	<version>x.y.z</version>
</dependency>

New methods available

removeNulls()

This method will remove all occurences of null within a list. Elements in the returned list will be in the same order as they were in the original list. This is the same behaviour as calling findAll{ it != null } on a list but the intent is more clear.

assert [1, false, null, '', 2].removeNulls() == [1, false, '', 2]

Releases

2.0.2 (current version)
Fixed issue #20

2.0.1
Fixed bug where removeNulls() removed items which weren’t null but which were falsey

2.0.0
Updated return types of tailIfAny() and removeNulls() from Object to List
Changed package names (in preparation of publishing to maven central repo)

1.2.0
Added new method: removeNulls()

1.1.0
Switched to semantic versioning (no functional changes)

1.1
Improved some tests (no functional changes)

1.0
Initial release
New methods available: only(), firstIfAny(), lastIfAny(), headIfAny(), tailIfAny(), and onlyIfAny()

Thanks

Learning about the Groovy extension mechanism and inspiration to try writing an extension myself come from Tim YatesGroovy Common Extensions project. The Gradle build file here is based heavily on his from that project, too.


Articles

  • coming soon...