19 |
20 | <#include "footer.ftl">
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Licensed under the Apache License, Version 2.0 (the "License");
2 | you may not use this file except in compliance with the License.
3 | You may obtain a copy of the License at
4 |
5 | http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | Unless required by applicable law or agreed to in writing, software
8 | distributed under the License is distributed on an "AS IS" BASIS,
9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 |
11 | See the License for the specific language governing permissions and
12 | limitations under the License.
--------------------------------------------------------------------------------
/docs/assets/css/prettify.css:
--------------------------------------------------------------------------------
1 | .pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee}
2 |
--------------------------------------------------------------------------------
/src/main/java/groovy/stream/iterators/EmptyIterator.java:
--------------------------------------------------------------------------------
1 | package groovy.stream.iterators;
2 |
3 | import java.util.Iterator;
4 | import java.util.NoSuchElementException;
5 |
6 | public class EmptyIterator implements Iterator {
7 | @Override
8 | public boolean hasNext() {
9 | return false;
10 | }
11 |
12 | @Override
13 | public T next() {
14 | throw new NoSuchElementException( "EmptyIterator contains no elements" ) ;
15 | }
16 |
17 | @Override
18 | public void remove() {
19 | throw new UnsupportedOperationException( "Remove not supported on EmptyIterator" ) ;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/docs/templates/tags.ftl:
--------------------------------------------------------------------------------
1 | <#include "header.ftl">
2 |
3 | <#include "menu.ftl">
4 |
5 |
26 |
27 | <#include "footer.ftl">
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### A Lazy Groovy Generator.
2 |
3 | [](https://travis-ci.org/timyates/groovy-stream)[](https://coveralls.io/r/timyates/groovy-stream)
4 |
5 | ### Latest Version 0.9.0
6 |
7 | Documentation is embarrassingly out of date...
8 |
9 | Best place may be the Javadoc (has compiled examples in it)
10 | http://timyates.github.io/groovy-stream/javadoc/index.html?groovy/stream/Stream.html
11 |
12 | Out of date usage, news, etc. can be found here: http://timyates.github.com/groovy-stream/ or http://timyates.github.com/groovy-stream/main.html
13 |
14 | The first casualty of lack-of-time is documentation :-(
15 |
--------------------------------------------------------------------------------
/src/main/java/groovy/stream/functions/Predicate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package groovy.stream.functions ;
18 |
19 | /**
20 | * Given a value of type {@code T}, returns a {@code boolean}.
21 | *
22 | * @author Tim Yates
23 | * @since 0.8
24 | * @param The type of the input variable.
25 | */
26 | public interface Predicate {
27 | boolean call( T value ) ;
28 | }
--------------------------------------------------------------------------------
/docs/templates/feed.ftl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | JBake
5 | ${config.site_host}
6 |
7 | JBake Bootstrap Template
8 | en-gb
9 | ${published_date?string("EEE, d MMM yyyy HH:mm:ss Z")}
10 | ${published_date?string("EEE, d MMM yyyy HH:mm:ss Z")}
11 |
12 | <#list published_posts as post>
13 |
14 | <#escape x as x?xml>${post.title}#escape>
15 | ${config.site_host}${post.uri}
16 | ${post.date?string("EEE, d MMM yyyy HH:mm:ss Z")}
17 | ${post.uri}
18 |
19 | <#escape x as x?xml>
20 | ${post.body}
21 | #escape>
22 |
23 |
24 | #list>
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/main/java/groovy/stream/functions/Function.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package groovy.stream.functions ;
18 |
19 | /**
20 | * Describes a function which transforms a value of type {@code T} to one of type {@code S}.
21 | *
22 | * @author Tim Yates
23 | * @since 0.8
24 | * @param The input type
25 | * @param The output type
26 | */
27 | public interface Function {
28 | S call( T value ) ;
29 | }
--------------------------------------------------------------------------------
/src/test/groovy/groovy/stream/ObjectTests.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package groovy.stream
18 |
19 | class ObjectTests extends spock.lang.Specification {
20 | def "test obj appender"() {
21 | setup:
22 | def stream = Stream.from { 1 }
23 |
24 | when:
25 | def result = stream.take( 4 ).collect()
26 |
27 | then:
28 | result == [ 1, 1, 1, 1 ]
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/groovy/stream/functions/IndexedPredicate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package groovy.stream.functions ;
18 |
19 | /**
20 | * Given a value of type {@code T} and an {@link Integer} index, returns a {@code boolean}.
21 | *
22 | * @author Tim Yates
23 | * @since 0.8
24 | * @param The type of the input variable.
25 | */
26 | public interface IndexedPredicate {
27 | boolean call( T value, Integer index ) ;
28 | }
--------------------------------------------------------------------------------
/src/test/groovy/groovy/stream/ReadmeTests.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package groovy.stream
18 |
19 | class ReadmeTests extends spock.lang.Specification {
20 | def "first example"() {
21 | setup:
22 | def s = Stream.from x:1..2, y:1..4 filter { x + y == 4 }
23 |
24 | when:
25 | def result = s.collect()
26 |
27 | then:
28 | result == [ [x:1, y:3], [x:2, y:2] ]
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/groovy/stream/functions/IndexedFunction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package groovy.stream.functions ;
18 |
19 | /**
20 | * Describes a function which takes a value of type {@code T} plus an {@link Integer} index,
21 | * and returns a value of type {@code S}
22 | *
23 | * @author Tim Yates
24 | * @since 0.8
25 | * @param The input type
26 | * @param The output type
27 | */
28 | public interface IndexedFunction {
29 | S call( T value, Integer index ) ;
30 | }
--------------------------------------------------------------------------------
/src/test/groovy/groovy/stream/ConcatenationTests.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package groovy.stream
18 |
19 | class ConcatenationTests extends spock.lang.Specification {
20 | def "quick test"() {
21 | setup:
22 | def streamA = Stream.from 1..3
23 | def streamB = Stream.from 'a'..'c'
24 |
25 | when:
26 | def result = streamA.concat( streamB ).collect()
27 | then:
28 | result == [ 1, 2, 3, 'a', 'b', 'c' ]
29 | }
30 | }
--------------------------------------------------------------------------------
/src/main/java/groovy/stream/functions/Function2.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package groovy.stream.functions ;
18 |
19 | /**
20 | * Describes a function which takes one value of type {@code T} and another of type {@code U}
21 | * and transforms them to one of type {@code S}
22 | *
23 | * @author Tim Yates
24 | * @since 0.8
25 | * @param The first input type
26 | * @param The second input type
27 | * @param The output type
28 | */
29 | public interface Function2 {
30 | S call( T value, U value2 ) ;
31 | }
--------------------------------------------------------------------------------
/docs/assets/css/base.css:
--------------------------------------------------------------------------------
1 | /* Sticky footer styles
2 | -------------------------------------------------- */
3 |
4 | html,
5 | body {
6 | height: 100%;
7 | /* The html and body elements cannot have any padding or margin. */
8 | }
9 |
10 | /* Wrapper for page content to push down footer */
11 | #wrap {
12 | min-height: 100%;
13 | height: auto !important;
14 | height: 100%;
15 | /* Negative indent footer by it's height */
16 | margin: 0 auto -60px;
17 | }
18 |
19 | /* Set the fixed height of the footer here */
20 | #push,
21 | #footer {
22 | height: 60px;
23 | }
24 | #footer {
25 | background-color: #f5f5f5;
26 | padding: 0;
27 | }
28 |
29 | /* Lastly, apply responsive CSS fixes as necessary */
30 | @media (max-width: 767px) {
31 | #footer {
32 | margin-left: -20px;
33 | margin-right: -20px;
34 | padding-left: 20px;
35 | padding-right: 20px;
36 | }
37 | }
38 |
39 | /* Custom page CSS
40 | -------------------------------------------------- */
41 | /* Not required for template or sticky footer method. */
42 |
43 | #wrap > .container {
44 | padding-top: 60px;
45 | }
46 | .container .credit {
47 | margin: 20px 0;
48 | }
49 |
50 | /*code {
51 | font-size: 80%;
52 | }*/
--------------------------------------------------------------------------------
/docs/content/map.adoc:
--------------------------------------------------------------------------------
1 | Map Functions
2 | =============
3 | Tim Yates
4 | 2014-02-04
5 | :jbake-type: page
6 | :jbake-tags: documentation, manual
7 | :jbake-status: published
8 |
9 | Map functions transform elements in the Stream from one form to another.
10 |
11 | At it's simplest level, it looks like the following:
12 |
13 | [source,groovy]
14 | ----
15 | include::../../src/test/groovy/asciidoc/MapExamples.groovy[tags=simple_example,indent=0]
16 | ----
17 |
18 | You can also pass the index into the map call by calling `mapWithIndex`:
19 |
20 | [source,groovy]
21 | ----
22 | include::../../src/test/groovy/asciidoc/MapExamples.groovy[tags=index_example,indent=0]
23 | ----
24 |
25 | There also exists a `flatMap` variant, so you can return a Collection of values and
26 | each of these will be iterated first, before the underlying Stream is queried again for
27 | the next sequence in the list:
28 |
29 | [source,groovy]
30 | ----
31 | include::../../src/test/groovy/asciidoc/MapExamples.groovy[tags=flat_example,indent=0]
32 | ----
33 |
34 | And of course, this has a `flatMapWithIndex` variant.
35 |
36 | [source,groovy]
37 | ----
38 | include::../../src/test/groovy/asciidoc/MapExamples.groovy[tags=flat_index_example,indent=0]
39 | ----
--------------------------------------------------------------------------------
/src/main/java/groovy/stream/functions/IndexedFunction2.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package groovy.stream.functions ;
18 |
19 | /**
20 | * Describes a function which takes one value of type {@code T}, another of type {@code U} and
21 | * an {@link Integer} index, and returns a value of type {@code S}.
22 | *
23 | * @author Tim Yates
24 | * @since 0.8
25 | * @param The first input type
26 | * @param The second input type
27 | * @param The output type
28 | */
29 | public interface IndexedFunction2 {
30 | S call( T value, U value2, Integer index ) ;
31 | }
--------------------------------------------------------------------------------
/docs/templates/footer.ftl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
10 |
11 |
13 |
14 |
15 |
16 |
17 |
28 |
29 |