dtonhofer
Functional Programming in Java, Second Edition: p. 55 "Compare.java" can be further simplified
On page 55, we see Compare.java
final Function<Person, String> byName = person -> person.getName();
people.stream()
   .sorted(comparing(byName));
However, this can be further simplified to:
people.stream()
   .sorted(comparing(Person::getName));
On the same page, more from Compare.java:
final Function<Person, Integer> byAge = person -> person.getAge();
final Function<Person, String> byTheirName = person -> person.getName();
printPeople("Sorted in ascending order by age, then name: ",
                people.stream()
                        .sorted(comparing(byAge).thenComparing(byTheirName))
                        .collect(toList());
which can be simplified similarly to:
printPeople("Sorted in ascending order by age, then name: ",
                people.stream()
                        sorted(comparing(Person::getAge).thenComparing(Person::getName))
                        .collect(toList());
but which would be even better by separating the list generation and output tasks:
List<Person> asc =
                people.stream()
                        .sorted(comparing(Person::getAge).thenComparing(Person::getName))
                        .collect(toList());
        printPeople("Sorted in ascending order by age, then name: ", asc);
…all according to the JavaDoc for Comparator:
P.S.
Would it be clearer to explicitly write the class from which comparing() comes instead of assuming it has been imported statically?  Like this:
people.stream()
   .sorted(Comparator.comparing(Person::getName));
instaed of
people.stream()
   .sorted(comparing(Person::getName));
Note that the collect()call
people.stream()
   .sorted(comparing(byAge).thenComparing(byTheirName))
   .collect(toList()));
…also assume a statically imported toList(). On the other hand, compare/fpij/OlderThan20.java on page 58 is explicit:
List<Person> olderThan20 =
   people.stream()
      .filter(person -> person.getAge() > 20)
      .collect(Collectors.toList());
 
  	            Popular Pragmatic Bookshelf topics
                        
                      
                      
                Title: Design and Build Great Web APIs - typo “https://company-atk.herokuapp.com/2258ie4t68jv” (page 19, third bullet in URL list) 
Typo:...
              
            
            
          
              New
                I can’t setup the Rails source code. This happens in a working directory containing multiple (postgres) Rails apps. 
With: 
ruby-3.0.0 
s...
              
            
            
          
              New
                First, the code resources: 
Page 237:  rumbl_umbrella/apps/rumbl/mix.exs 
Note:  That this file is missing. 
Page 238: rumbl_umbrella/app...
              
            
            
          
              New
                This is as much a suggestion as a question, as a note for others. 
Locally the SGP30 wasn’t available, so I ordered a SGP40. On page 53, ...
              
            
            
          
              New
                When running tox for the first time, I got the following error: 
ERROR: InterpreterNotFound: python3.10 
I realised that I was running ...
              
            
            
          
              New
                I got this error when executing the plot files on macOS Ventura  13.0.1 with Python 3.10.8 and matplotlib 3.6.1: 
programming_ML/code/03_...
              
            
            
          
              New
                Hello @herbert ! Trying to get the very first “Hello, Bracket Terminal!" example to run (p. 53). I develop on an Amazon EC2 instance runn...
              
            
            
          
              New
                Docker-Machine became part of the Docker Toolbox, which was deprecated in 2020, long after Docker Desktop supported Docker Engine nativel...
              
            
            
          
              New
                root_layout: {PentoWeb.LayoutView, :root}, 
This results in the following following error: 
no “root” html template defined for PentoWeb...
              
            
            
          
              New
                From page 13: 
On Python 3.7, you can install the libraries with pip by running these commands inside a Python venv  using Visual Studio ...
              
            
            
          
              New
Other popular topics
                        
                      
                      
                @AstonJ prompted me to open this topic after I mentioned in the lockdown thread how I started to do a lot more for my fitness. 
https://f...
              
            
            
          
              New
                Please tell us what is your preferred monitor setup for programming(not gaming) and why you have chosen it. 
Does your monitor have eye p...
              
            
            
          
              New
                There’s a whole world of custom keycaps out there that I didn’t know existed! 
Check out all of our Keycaps threads here: 
https://forum....
              
            
            
          
              New
                I have seen the keycaps I want - they are due for a group-buy this week but won’t be delivered until October next year!!! :rofl: 
The Ser...
              
            
            
          
              New
                Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
              
            
            
          
              New
                Author Spotlight 
Jamis Buck 
@jamis 
This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
              
            
            
          
              New
                I am trying to crate a game for the Nintendo switch, I wanted to use Java as I am comfortable with that programming language. Can you use...
              
            
            
          
              New
                zig/http.zig at 7cf2cbb33ef34c1d211135f56d30fe23b6cacd42 · ziglang/zig. 
General-purpose programming language and toolchain for maintaini...
              
            
            
              
          
              New
                Node.js v22.14.0 has been released. 
Link: Release 2025-02-11, Version 22.14.0 'Jod' (LTS), @aduh95 · nodejs/node · GitHub
              
            
            
              
          
              New
                Ask Me Anything with 
Mark Volkmann 
@mvolkmann 
On February 24 and 25, we are giving you a chance to ask questions of PragProg author M...
              
            
            
          
              New
Categories:
Sub Categories:
Popular Portals
- /elixir
 - /rust
 - /ruby
 - /wasm
 - /erlang
 - /phoenix
 - /keyboards
 - /python
 - /rails
 - /js
 - /security
 - /go
 - /swift
 - /vim
 - /clojure
 - /haskell
 - /emacs
 - /java
 - /svelte
 - /onivim
 - /typescript
 - /kotlin
 - /c-plus-plus
 - /crystal
 - /tailwind
 - /react
 - /gleam
 - /ocaml
 - /elm
 - /flutter
 - /vscode
 - /ash
 - /html
 - /opensuse
 - /centos
 - /php
 - /zig
 - /deepseek
 - /scala
 - /lisp
 - /textmate
 - /sublime-text
 - /react-native
 - /nixos
 - /debian
 - /agda
 - /kubuntu
 - /arch-linux
 - /django
 - /deno
 - /revery
 - /ubuntu
 - /manjaro
 - /nodejs
 - /spring
 - /diversity
 - /lua
 - /julia
 - /slackware
 - /c
 
    





