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

Tutorial1, 2 (FP, Dictionary, uniqueMap) #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

dev-yong
Copy link

@dev-yong dev-yong commented Nov 12, 2019

  1. functional programming
  2. dictionary + functional programming
  3. uniqueMap

@dev-yong dev-yong changed the title Tutorial1 Tutorial1 (FP + Dictionary) Nov 12, 2019
@dev-yong dev-yong changed the title Tutorial1 (FP + Dictionary) Tutorial1, 2 (FP, Dictionary, uniqueMap) Nov 12, 2019
let dictionary = champs.reduce(into: [String: String]()) {
$0[$1.key] = $1.name
}
let names = selectedIndexes.map {
Copy link
Owner

Choose a reason for hiding this comment

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

익명함수를 제거하면 더 읽기 좋은 코드가 될 수 있습니다.


// TODO: selectedIndexes는 챔피언 목록(champs)의 key 번호 들이다. selectedIndexes에 명시된 순서대로 챔피언들의 이름(name)을 나열하라
let names: [String] = []

let dictionary = champs.reduce(into: [String: String]()) {
Copy link
Owner

Choose a reason for hiding this comment

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

reduce를 사용해보셨군요! 좋습니다.

let selectedIndexes = try decoder.decode([Int?].self, from: selectedIndexesData!)

extension Array where Element: Equatable {
func uniqueMap() -> Self {
Copy link
Owner

Choose a reason for hiding this comment

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

좋은 시도 같습니다. 어떤 이유로 만드셨는지 설명을 붙여주시면, 더 좋은 리뷰를 드릴 수 있을 것 같아요.

Copy link
Author

Choose a reason for hiding this comment

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

배열의 인자들에 대하여 유일한 값들로 이루어져 있으며, 그 순서를 보장한 배열을 만들고자하였습니다.
리뷰들 감사드립니다!

Tutorial/Tutorial2.playground/Contents.swift Show resolved Hide resolved
String(describing: $0)
}
.compactMap { key in
champs.first { $0.key == key }?.name
Copy link
Owner

Choose a reason for hiding this comment

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

uniqueMap 같이 이곳도 적절한 이름을 가진 함수를 만들 수 있을 것 같아요

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