Created
February 16, 2012 14:39
-
-
Save timyates/1845334 to your computer and use it in GitHub Desktop.
Working with groovy snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git clone [email protected]:timyates/groovy-core.git | |
Cloning into groovy-core... | |
Warning: No xauth data; using fake authentication data for X11 forwarding. | |
remote: Counting objects: 144322, done. | |
remote: Compressing objects: 100% (32204/32204), done. | |
remote: Total 144322 (delta 92128), reused 144110 (delta 91947) | |
Receiving objects: 100% (144322/144322), 106.70 MiB | 5.17 MiB/s, done. | |
Resolving deltas: 100% (92128/92128), done. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cd groovy-core/ | |
(master) $ git remote add upstream https://github.com/groovy/groovy-core.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(master) $ git remote -v | |
origin [email protected]:timyates/groovy-core.git (fetch) | |
origin [email protected]:timyates/groovy-core.git (push) | |
upstream https://github.com/groovy/groovy-core.git (fetch) | |
upstream https://github.com/groovy/groovy-core.git (push) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(master) $ git pull upstream master | |
From https://github.com/groovy/groovy-core | |
* branch master -> FETCH_HEAD | |
Already up-to-date. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def result = list.drop( 1 ).inject( list.head() ) { a, b -> b << a } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def people = [ [ 'tim', 'dave', 'chris' ], | |
[ 'stuart', 'harry', 'tim' ], | |
[ 'bert', 'tim', 'ernie' ] ] | |
def inAll = people.drop( 1 ).inject( people.head() ) { a, b -> | |
a.intersect( b ) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def result = list.inject { a, b -> b << a } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def inAll = people.inject { a, b -> a.intersect( b ) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(master) $ git checkout -b onearginject | |
Switched to a new branch 'onearginject' | |
(onearginject) $ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void testOneArgListInject() { | |
// Check basic functionality | |
def value = [ 1, 2, 3 ].inject { c, item -> c + item } | |
assert value == 6 | |
// Check a use-case | |
value = [ [ 'tim', 'dave', 'chris' ], | |
[ 'stuart', 'harry', 'tim' ], | |
[ 'bert', 'tim', 'ernie' ] ] | |
assert value.inject { a, b -> a.intersect( b ) } == ['tim'] | |
// Check edges | |
assert [].inject { a, b -> a + b } == null | |
assert [ 1 ].inject { a, b -> a + b } == 1 | |
assert [ 1, 2 ].inject { a, b -> a + b } == 3 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment