본문 바로가기 메뉴 바로가기

Peppo

프로필사진
  • 글쓰기
  • 관리
  • 태그
  • 방명록
  • RSS

Peppo

검색하기 폼
  • 분류 전체보기 (221)
    • Story (13)
    • iOS (143)
      • Error (11)
    • 알고리즘 (43)
    • ETC (7)
    • React-Native (0)
    • CS (Computer science) (3)
  • 방명록

swift 고차함수 (2)
[Swift] compactMap, flatMap

오늘은 고차함수 compactMap과 flatMap에 대해 공부해 보려고 합니다. 먼저 예시로 바로 들어볼게요. 아래와 같은 배열이 있습니다. let arr = [nil, 1, 2, nil, nil, 5] 여기서 nil을 없애고 배열을 반환하고 싶으면 ? 이때 compactMap, flatMap 을 사용하면 돼요! let arr = [nil, 1, 2, nil, nil, 5] let compactMap1 = arr.compactMap { $0 } let flatMap1 = arr.flatMap { $0 } print("compact:\(compactMap1)") // compact:[1, 2, 5] print("flatMap:\(flatMap1)") // flatMap:[1, 2, 5] 이렇게 맛보기만 ..

iOS 2022. 9. 1. 00:12
[Swift] 고차함수 - reduce

고차함수에서 피해가고 싶었던 reduce ... 요즘 알고리즘 문제를 풀면서 모르면 안되겠다는 생각이 들어 한번 파보려고 합니다. 👊 공식문서 컨테이너의 요소들을 결합한 결과를 반환합니다. 예제를 통해서 보시죠!! 예제 1 let numbers: [Int] = [1, 2, 3, 4] var sum = numbers.reduce(initialResult: Result>, Result(Result, Int) throws -> Result(_ partialResult: Result, Int) throws -> Result) 먼저 initialResult, nextPartialResult 부분을 볼게요. initialResult: 결합을 시작하기전 초기 값을 지정 합니다. nextPartialResult: 요..

iOS 2022. 5. 13. 11:03
이전 1 다음
이전 다음
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
  • Peppo's Github
TAG
  • Class
  • CS 네트워크
  • 원티드 프리온보딩
  • swift programmers
  • RIBs tutorial
  • Swift final
  • ios
  • removeLast()
  • Swift joined()
  • swift (programmers)
  • Swift 프로그래머스
  • Swift Error Handling
  • swift protocol
  • Swift inout
  • 2023년 회고
  • iOS error
  • Swift init
  • Combine: Asynchronous Programming with Swift
  • Swift
  • Swift joined
  • Swift 내림차순
  • Swift Leetcode
  • Swift ModernRIBs
  • swift property
  • RTCCameraVideoCapturer
  • Swift 알고리즘
  • Swift RIBs
  • swift 고차함수
  • swift reduce
  • Swift 프로퍼티
more
«   2025/05   »
일 월 화 수 목 금 토
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함

Blog is powered by Tistory / Designed by Tistory

티스토리툴바