Skip to content

Commit 4601555

Browse files
committed
small change
1 parent c3c1368 commit 4601555

File tree

4 files changed

+19
-26
lines changed

4 files changed

+19
-26
lines changed

build/build.java

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -410,22 +410,23 @@ private static String shortName(String filename) {
410410
return filename.substring(index + 1);
411411
}
412412

413-
private interface Generator<T> {
414-
void generate(List<String> lines, T attachment) throws IOException;
413+
@FunctionalInterface
414+
private interface Action<T> {
415+
void execute(List<String> lines, T attachment) throws IOException;
415416

416-
default Generator<T> and(Generator<T> generator) {
417+
default Action<T> and(Action<? super T> action) {
417418
return (lines, attachment) -> {
418-
generate(lines, attachment);
419-
generator.generate(lines, attachment);
419+
execute(lines, attachment);
420+
action.execute(lines, attachment);
420421
};
421422
}
422423

423-
static Generator<String> write(Generator<Path> writeMethod, Path folder, String extension) {
424-
return (lines, rawFilename) -> writeMethod.generate(lines, folder.resolve(rawFilename + extension));
424+
static Action<String> create(Action<Path> action, Path folder, String extension) {
425+
return (lines, rawFilename) -> action.execute(lines, folder.resolve(rawFilename + extension));
425426
}
426427
}
427428

428-
private static void generate(List<Path> paths, Generator<String> generator) throws IOException {
429+
private static void generate(List<Path> paths, Action<String> action) throws IOException {
429430
for(var path: paths) {
430431
var rawFilename = removeExtension(path.getFileName().toString());
431432

@@ -435,7 +436,7 @@ private static void generate(List<Path> paths, Generator<String> generator) thro
435436
lines = stream.dropWhile(LineKind.is(LineKind.TEXT)).dropWhile(LineKind.is(LineKind.BLANK)).collect(Collectors.toList());
436437
}
437438

438-
generator.generate(lines, rawFilename);
439+
action.execute(lines, rawFilename);
439440
}
440441
}
441442

@@ -454,7 +455,7 @@ private static List<Path> gatherFiles(Path directory, Predicate<String> filter)
454455
}
455456
}
456457

457-
private static /*record*/ class Config {
458+
private static record Config(Optional<Kind> index, Set<Kind> kinds, Map<Kind, Path> folderMap) {
458459
private enum Kind {
459460
MARKDOWN(".md", build::writeMarkDown),
460461
NOTEBOOK(".ipynb", build::writeJupyter),
@@ -469,12 +470,12 @@ static Optional<Kind> of(String name) {
469470

470471
private final String propertyName;
471472
private final String extension;
472-
private final Generator<Path> generator;
473+
private final Action<Path> action;
473474

474-
private Kind(String extension, Generator<Path> generator) {
475+
private Kind(String extension, Action<Path> action) {
475476
this.propertyName = name().toLowerCase();
476477
this.extension = extension;
477-
this.generator = generator;
478+
this.action = action;
478479
}
479480

480481
Path folder(Properties properties) {
@@ -486,16 +487,6 @@ private static Optional<String> getProperty(Properties properties, String proper
486487
return Optional.ofNullable(properties.getProperty(propertyName));
487488
}
488489

489-
private final Optional<Kind> index;
490-
private final Set<Kind> kinds;
491-
private final Map<Kind, Path> folderMap;
492-
493-
private Config(Optional<Kind> index, Set<Kind> kinds, Map<Kind, Path> folderMap) {
494-
this.index = index;
495-
this.kinds = kinds;
496-
this.folderMap = folderMap;
497-
}
498-
499490
Path folder(Kind kind) {
500491
return folderMap.get(kind);
501492
}
@@ -523,8 +514,8 @@ public static void main(String[] args) throws IOException {
523514
createDirectories(config.folder(kind));
524515
}
525516

526-
// create generator
527-
var generator = config.kinds.stream().map(k -> Generator.write(k.generator, config.folder(k), k.extension)).reduce(Generator::and).orElseThrow();
517+
// create action
518+
var generator = config.kinds.stream().map(k -> Action.create(k.action, config.folder(k), k.extension)).reduce(Action::and).orElseThrow();
528519

529520
// gather files and generate
530521
var files = gatherFiles(Path.of("."), name -> name.endsWith(".jsh"));

chapter25-stream.jsh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ System.out.println(Arrays.stream(squareRoots).limit(10).boxed().collect(toList()
326326
// ## Limitations
327327

328328
// ### Reusing stream objects
329+
// You can not reuse a stream for several queries
329330
var stream = Stream.of(1, 2, 3);
330331
System.out.println(stream.count());
331332
System.out.println(stream.count());

guide/chapter25-stream.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ You have to use specialized method (resp `findFirst()` and `forEachOrdered()`) t
394394
## Limitations
395395

396396
### Reusing stream objects
397+
You can not reuse a stream for several queries
397398
```java
398399
var stream = Stream.of(1, 2, 3);
399400
System.out.println(stream.count());

jupyter/chapter25-stream.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@
626626
{
627627
"cell_type": "markdown",
628628
"metadata": {},
629-
"source": ["### Reusing stream objects\n"]
629+
"source": ["### Reusing stream objects\n", "You can not reuse a stream for several queries\n"]
630630
}
631631
,
632632
{

0 commit comments

Comments
 (0)