1차 수정 버전 - 김성훈#11
Open
Seonghun23 wants to merge 7 commits intowanbok:masterfrom
Open
Conversation
wanbok
reviewed
Nov 14, 2019
| // 그 결과 결과값을 바로 캐스팅하여 가져올 수 있게 되었다. | ||
| // 이전 코드 보단 한층 깔끔한 느낌이다. | ||
| // 다만 flatMap으로 튜플로 변경하는 부분의 코드가 가독성이 좋지 않고 지저분하다. | ||
| // 저것도 더 깔끔하게 변경할 수 있을지 고민해 봐야 겠다. |
| let names: [String] = [] | ||
|
|
||
| let champsDict = champs? | ||
| .flatMap { [$0["key"] as? String: $0["name"] as? String] } |
Owner
There was a problem hiding this comment.
이곳의 결과물은 Dictionary일까요 Array일까요?
champs -> flatMap -> reduce 로 바뀌는 과정의 타입 변화를 살펴보면 힌트가 있을 것 같습니다.
Author
There was a problem hiding this comment.
flatMap 결과값은 Tuple을 담고 있는 Array입니다.
다만 타입추론으로 reduce를 거치며 이Tuple의 key에 자료형이 champsDict의 키에 자료형과 맞춰지게 되어 결과적으로 champsDict의 자료형은 Optional String을 키값으로 가지는 Dictionary가 되었습니다.
보통은 Codable을 이용하지만, Codable을 사용하지 않고 고계 함수만으로 개선하려 하니 더 고민이었던 것 같습니다.
Author
|
@wanbok 리뷰 감사합니다. |
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.