Skip to content

support yaml as format for patterns #70

@hallvard

Description

@hallvard

I'm not a bit fan of yaml, but in the case of the patterns, it's IMO preferable, since multi-line code snippets are easier to read and write. I know you are known to dislike and bash yaml, and in general I agree, but in this case ...

E.g. here's part of the the collectors-teeing pattern in yaml:

oldApproach: Two Passes
modernApproach: teeing()
oldCode: |
  long count = items.stream().count();
  double sum = items.stream()
      .mapToDouble(Item::price)
      .sum();
  var result = new Stats(count, sum);
modernCode: |
  var result = items.stream().collect(
      Collectors.teeing(
          Collectors.counting(),
          Collectors.summingDouble(Item::price),
          Stats::new
      )
  );
summary: Compute two aggregations in a single stream pass.
explanation: Collectors.teeing() sends each element to two downstream collectors and merges the results. This avoids streaming the data twice or using a mutable accumulator.
whyModernWins:
  - icon: ⚡
    title: Single pass
    desc: Process the stream once instead of twice.
  - icon: 🧩
    title: Composable
    desc: Combine any two collectors with a merger function.

I will create a PR for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions