Skip to content
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

[이태훈] 3주차 미션 제출합니다. #10

Merged
merged 4 commits into from
Aug 27, 2023
Merged

[이태훈] 3주차 미션 제출합니다. #10

merged 4 commits into from
Aug 27, 2023

Conversation

xogns1514
Copy link
Contributor

모던 자바 인 액션 소스 코드 공부 Repo: https://github.com/xogns1514/modernJava.git

@binary-ho binary-ho self-requested a review August 22, 2023 22:02

- 게으른 특성으로 인한 최적화
- limit연산, 쇼트 서킷: 300 칼로리가 넘는 요리는 여러 개지만 처음 3개만 선택됨
- 루프 퓨전(loop fusion): filter와 map은 서로 다은 연산이지만 한 과정으로 병합
Copy link
Member

@binary-ho binary-ho Aug 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이미 아시겠지만, 중간에 sorted가 있으면, sorted 전에 루프 퓨전을 끊습니다.
결과물이 있어야 정렬할 수 있으니까요!

아래 코드는
3
3
1
1
2
2
ㅡㅡㅡㅡㅡㅡㅡㅡㅡ(보기 쉬우라고 넣은 공백)
1
1
2
2
3
3

이렇게 출력됩니다.
루프 퓨전이 sorted 이전까지 일어난 다음 한번 정렬하고, 다음 출력을 이어갑니다

List<Integer> list = List.of(3, 1, 2);
      
        list.stream()
            .peek(System.out::println)
            .peek(System.out::println)
            .sorted()
            .peek(System.out::println)
            .forEach(System.out::println);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

결합불가능한 연산에서는 루프퓨전이 끊기는군요.이해했습니다!


→ 스트림 파이프라인의 개념은 빌터 패턴과 유사하다.

❓빌더 패턴: 복잡한 객체의 생성 과정과 표현 방법을 분리하여 다양한 구성의 인스턴스를 만드는 생성 패턴
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@binary-ho binary-ho merged commit deba8fb into develop Aug 27, 2023
@binary-ho
Copy link
Member

LGTM! 고생 많으셨습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants