Skip to content

Conversation

@LeeJuHwan
Copy link
Contributor

Pull Request Java Playground Solve Mission

Checklist


👍 확인:

  • 리뷰어를 설정 했습니다
  • 해결 한 문제에 대해 작성 했습니다
  • 라벨을 설정 했습니다

미션 내용


내용

  1. 익명 클래스를 람다로 전환 미션 진행
  2. 람다를 활용해 중복 제거
  3. war-and-peace.txt 파일을 읽어 printLongestWordTop100() 메서드 구현
  4. Optional 을 활용해 조건에 따른 반환

Note

Comment

다른 미션을 수행하면서 StreamOptional 을 사용하고 있었기 때문에 크게 어렵지 않았던 것 같아요.

@LeeJuHwan LeeJuHwan added the blackjack-001/stream-lambda-optional 블랙잭 - 1. 자바 8 스트림, 람담, Optional label May 4, 2025
@LeeJuHwan LeeJuHwan self-assigned this May 4, 2025
@soyamilk0705
Copy link

미션 내용 잘봤습니다! optional 미션에서 User.ageIsInRange2() 함수를 저는 이런 식으로 풀었는데 같이 봐주시면 좋을 거 같아서 남겨요!

public static boolean ageIsInRange2(User user) {
    return Optional.ofNullable(user)
            .map(User::getAge)
            .filter(age -> age != null)
            .filter(age -> age >= 30)
            .filter(age -> age <= 45)
            .isPresent();
}

@LeeJuHwan
Copy link
Contributor Author

미션 내용 잘봤습니다! optional 미션에서 User.ageIsInRange2() 함수를 저는 이런 식으로 풀었는데 같이 봐주시면 좋을 거 같아서 남겨요!

public static boolean ageIsInRange2(User user) {
    return Optional.ofNullable(user)
            .map(User::getAge)
            .filter(age -> age != null)
            .filter(age -> age >= 30)
            .filter(age -> age <= 45)
            .isPresent();
}

확실히 filter 메서드 하나에서 모든걸 처리하려고 하는 것 보다 체이닝을 여러번 걸어서 가독성을 높이는게 더 좋은 방향인 것 같네요!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blackjack-001/stream-lambda-optional 블랙잭 - 1. 자바 8 스트림, 람담, Optional

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants