Swift 사용하다보면 map 류를 엄청 많이 사용한다... 갓갓... flatmap 부터 각종 라이브러리에도 map 구현체가 많다.
그래서 map의 기본 원리를 알아보려고한다. Map 이라는 것은 map(_:) | Apple Developer Documentation 애플공식 문서에도 나와있다 시피 Sequence's element 들을 주어진 클로저로 매핑된 어레이로 던져 주는 것이다.
간단히 구현을 해보면 extension Collection { func ownMAP(transform: (Element) -> U) -> any Collection { var mappedArray: [U] = [] for element in self { mappedArray.append(transform(element)) } return mappedArray } func tryOwnMap(transform: (Element) throws -> U) rethrows -> any Co...