Skip to main content
forgot some parens looks like thx
Source Link
mmathis
  • 5.6k
  • 26
  • 35

Java has the Optional::stream function, and streams have flatMap. These two together will let you write java code that is very similar to the JavaScript code in https://softwareengineering.stackexchange.com/a/387859/3307

values.stream()
      .flatMap( v -> (include(v) ? Optional.empty() : Optional.of(v*2)).stream() )

// added some parens

Java has the Optional::stream function, and streams have flatMap. These two together will let you write java code that is very similar to the JavaScript code in https://softwareengineering.stackexchange.com/a/387859/3307

values.stream()
      .flatMap( v -> (include(v) ? Optional.empty() : Optional.of(v*2)).stream() )

// added some parens

Java has the Optional::stream function, and streams have flatMap. These two together will let you write java code that is very similar to the JavaScript code in https://softwareengineering.stackexchange.com/a/387859/3307

values.stream()
      .flatMap( v -> (include(v) ? Optional.empty() : Optional.of(v*2)).stream() )
forgot some parens looks like thx
Source Link

Java has the Optional::stream function, and streams have flatMap. These two together will let you write java code that is very similar to the JavaScript code in https://softwareengineering.stackexchange.com/a/387859/3307

values.stream()
      .flatMap( v -> (include(v) ? Optional.empty() : Optional.of(v*2)).stream() )

// added some parens

Java has the Optional::stream function, and streams have flatMap. These two together will let you write java code that is very similar to the JavaScript code in https://softwareengineering.stackexchange.com/a/387859/3307

values.stream()
      .flatMap( v -> (include(v) ? Optional.empty : Optional.of(v*2)).stream() )

Java has the Optional::stream function, and streams have flatMap. These two together will let you write java code that is very similar to the JavaScript code in https://softwareengineering.stackexchange.com/a/387859/3307

values.stream()
      .flatMap( v -> (include(v) ? Optional.empty() : Optional.of(v*2)).stream() )

// added some parens

Source Link

Java has the Optional::stream function, and streams have flatMap. These two together will let you write java code that is very similar to the JavaScript code in https://softwareengineering.stackexchange.com/a/387859/3307

values.stream()
      .flatMap( v -> (include(v) ? Optional.empty : Optional.of(v*2)).stream() )