feat: apply lambda, stream, Optional#1
Open
oliviarla wants to merge 1 commit intoobject-oriented-thinking:oliviarlafrom
Open
feat: apply lambda, stream, Optional#1oliviarla wants to merge 1 commit intoobject-oriented-thinking:oliviarlafrom
oliviarla wants to merge 1 commit intoobject-oriented-thinking:oliviarlafrom
Conversation
this-is-spear
left a comment
There was a problem hiding this comment.
늦게 리뷰드려서 죄송합니다. 😿
이번 미션을 진행하면서 저도 많이 배웠던 것 같아요!
이번 미션 수고 많으셨습니다. 🙇♂️
Comment on lines
+33
to
35
| public interface Conditional { | ||
| boolean test(Integer number); | ||
| } |
There was a problem hiding this comment.
Condition 인터페이스를 내부에 선언하신 이유가 있으실까요?
There was a problem hiding this comment.
그리고 test 말고도 좋은 메서드 이름이 있을 것 같아요!
Comment on lines
42
to
+47
| public static int sumAllEven(List<Integer> numbers) { | ||
| int total = 0; | ||
| for (int number : numbers) { | ||
| if (number % 2 == 0) { | ||
| total += number; | ||
| } | ||
| } | ||
| return total; | ||
| return sumAll(numbers, (integer)->{return integer%2==0;}); | ||
| } | ||
|
|
||
| public static int sumAllOverThree(List<Integer> numbers) { | ||
| int total = 0; | ||
| for (int number : numbers) { | ||
| if (number > 3) { | ||
| total += number; | ||
| } | ||
| } | ||
| return total; | ||
| return sumAll(numbers, (integer)->{return integer>3;}); |
There was a problem hiding this comment.
조건들도 메서드로 선언해서 깔끔하게 관리하는 것도 좋아보여요!
| List<String> words = Arrays.asList(contents.split("[\\P{L}]+")); | ||
|
|
||
| // TODO 이 부분에 구현한다. | ||
| words.stream().filter(w -> w.length() > 12).sorted(Comparator.comparing(String::length).reversed()).distinct().limit(100).map(String::toLowerCase).forEach(System.out::println); |
There was a problem hiding this comment.
이 방식으로 조건들을 한 번에 해결할 수 있군요! 멋집니다. 👍
|
|
||
| public static boolean ageIsInRange2(User user) { | ||
| return false; | ||
| return Optional.ofNullable(user).map(x -> x.getAge()).filter(x -> x >=30 && x <= 45).isPresent(); |
There was a problem hiding this comment.
람다를 추가적으로 사용할 수 있습니다.
Suggested change
| return Optional.ofNullable(user).map(x -> x.getAge()).filter(x -> x >=30 && x <= 45).isPresent(); | |
| return Optional.ofNullable(user).map(User::getAge).filter(x -> x >=30 && x <= 45).isPresent(); |
There was a problem hiding this comment.
x >=30 && x <= 45와 같은 조건을 의미있는 이름으로 메서드를 만들면 가독성이 더 좋을 것 같아요!
| return true; | ||
| } | ||
| }); | ||
| Car actual = car.move(() -> {return true;}); |
There was a problem hiding this comment.
Suggested change
| Car actual = car.move(() -> {return true;}); | |
| Car actual = car.move(() -> true); |
| return false; | ||
| } | ||
| }); | ||
| Car actual = car.move(() ->{return false;}); |
There was a problem hiding this comment.
Suggested change
| Car actual = car.move(() ->{return false;}); | |
| Car actual = car.move(() -> false); |
| } | ||
| } | ||
| return DEFAULT_USER; | ||
| return users.stream().filter(user -> user.matchName(name)).findAny().orElse(DEFAULT_USER); |
There was a problem hiding this comment.
findAny() 메서드를 사용하신 이유가 있을까요?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.