-
Notifications
You must be signed in to change notification settings - Fork 1
feat: apply lambda, stream, Optional #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: oliviarla
Are you sure you want to change the base?
feat: apply lambda, stream, Optional #1
Conversation
this-is-spear
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
늦게 리뷰드려서 죄송합니다. 😿
이번 미션을 진행하면서 저도 많이 배웠던 것 같아요!
이번 미션 수고 많으셨습니다. 🙇♂️
| public interface Conditional { | ||
| boolean test(Integer number); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Condition 인터페이스를 내부에 선언하신 이유가 있으실까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그리고 test 말고도 좋은 메서드 이름이 있을 것 같아요!
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
조건들도 메서드로 선언해서 깔끔하게 관리하는 것도 좋아보여요!
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 방식으로 조건들을 한 번에 해결할 수 있군요! 멋집니다. 👍
|
|
||
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
람다를 추가적으로 사용할 수 있습니다.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x >=30 && x <= 45와 같은 조건을 의미있는 이름으로 메서드를 만들면 가독성이 더 좋을 것 같아요!
| return true; | ||
| } | ||
| }); | ||
| Car actual = car.move(() -> {return true;}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
findAny() 메서드를 사용하신 이유가 있을까요?
No description provided.