Skip to content

Commit 542ce0e

Browse files
authored
Merge pull request #98 from javaevolved/copilot/implement-proof-for-slugs
Add proof files for all compilable pattern slugs
2 parents a78c2f7 + 07f7816 commit 542ce0e

File tree

105 files changed

+1958
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+1958
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
///usr/bin/env jbang "$0" "$@" ; exit $?
2+
//JAVA 25+
3+
import java.util.*;
4+
import java.util.stream.*;
5+
import static java.util.stream.Collectors.*;
6+
7+
/// Proof: collectors-teeing
8+
/// Source: content/collections/collectors-teeing.yaml
9+
record Item(String name, double price) {}
10+
record Stats(long count, double total) {}
11+
12+
void main() {
13+
var items = List.of(new Item("a", 10.0), new Item("b", 20.0));
14+
var result = items.stream().collect(
15+
Collectors.teeing(
16+
Collectors.counting(),
17+
Collectors.summingDouble(Item::price),
18+
Stats::new
19+
)
20+
);
21+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
///usr/bin/env jbang "$0" "$@" ; exit $?
2+
//JAVA 25+
3+
import java.util.*;
4+
5+
/// Proof: copying-collections-immutably
6+
/// Source: content/collections/copying-collections-immutably.yaml
7+
void main() {
8+
List<String> original = new ArrayList<>(List.of("a", "b", "c"));
9+
List<String> copy =
10+
List.copyOf(original);
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
///usr/bin/env jbang "$0" "$@" ; exit $?
2+
//JAVA 25+
3+
import java.util.*;
4+
5+
/// Proof: immutable-list-creation
6+
/// Source: content/collections/immutable-list-creation.yaml
7+
void main() {
8+
List<String> list =
9+
List.of("a", "b", "c");
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
///usr/bin/env jbang "$0" "$@" ; exit $?
2+
//JAVA 25+
3+
import java.util.*;
4+
5+
/// Proof: immutable-map-creation
6+
/// Source: content/collections/immutable-map-creation.yaml
7+
void main() {
8+
Map<String, Integer> map =
9+
Map.of("a", 1, "b", 2, "c", 3);
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
///usr/bin/env jbang "$0" "$@" ; exit $?
2+
//JAVA 25+
3+
import java.util.*;
4+
5+
/// Proof: immutable-set-creation
6+
/// Source: content/collections/immutable-set-creation.yaml
7+
void main() {
8+
Set<String> set =
9+
Set.of("a", "b", "c");
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
///usr/bin/env jbang "$0" "$@" ; exit $?
2+
//JAVA 25+
3+
import java.util.*;
4+
5+
/// Proof: map-entry-factory
6+
/// Source: content/collections/map-entry-factory.yaml
7+
void main() {
8+
var e = Map.entry("key", 42);
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
///usr/bin/env jbang "$0" "$@" ; exit $?
2+
//JAVA 25+
3+
import java.util.*;
4+
5+
/// Proof: reverse-list-iteration
6+
/// Source: content/collections/reverse-list-iteration.yaml
7+
void main() {
8+
List<String> list = List.of("a", "b", "c");
9+
for (String element : list.reversed()) {
10+
System.out.println(element);
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
///usr/bin/env jbang "$0" "$@" ; exit $?
2+
//JAVA 25+
3+
import java.util.*;
4+
5+
/// Proof: sequenced-collections
6+
/// Source: content/collections/sequenced-collections.yaml
7+
void main() {
8+
List<String> list = new ArrayList<>(List.of("a", "b", "c"));
9+
var last = list.getLast();
10+
var first = list.getFirst();
11+
var reversed = list.reversed();
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
///usr/bin/env jbang "$0" "$@" ; exit $?
2+
//JAVA 25+
3+
import java.util.*;
4+
import java.util.stream.*;
5+
6+
/// Proof: stream-toarray-typed
7+
/// Source: content/collections/stream-toarray-typed.yaml
8+
List<String> getNames() {
9+
return List.of("Alice", "Bob", "Charlie", "Dave");
10+
}
11+
12+
void main() {
13+
String[] arr = getNames().stream()
14+
.filter(n -> n.length() > 3)
15+
.toArray(String[]::new);
16+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
///usr/bin/env jbang "$0" "$@" ; exit $?
2+
//JAVA 25+
3+
import java.util.*;
4+
import java.util.stream.*;
5+
6+
/// Proof: unmodifiable-collectors
7+
/// Source: content/collections/unmodifiable-collectors.yaml
8+
void main() {
9+
Stream<String> stream = Stream.of("a", "b", "c");
10+
List<String> list = stream.toList();
11+
}

0 commit comments

Comments
 (0)