반응형

추론 3

<Reduce>함수 더하기 추론(조금...)

안녕하세요. KataRN입니다. 오늘은 Reduce 함수에 대해 알아보겠습니다.(이번엔 추론도 더해서 알아보겠습니다.) reduce 번역하면 "줄이다, 감소하다" 입니다. 하지만 이 함수는 덧셈 함수라고 할 수 있습니다. 우선 애플 공식문서를 봅시다. reduce(_:_:) Applies a closure that collects each element of a stream and publishes a final result upon completion. Declaration func reduce(_ initialResult: T, _ nextPartialResult: @escaping (T, Self.Output) -> T) -> Publishers.Reduce Return Value A publish..

<Filter> 함수 더하기 추론(조금...)

안녕하세요. KataRN입니다. 오늘은 Filter 함수에 대해 알아보겠습니다. 공식문서부터 알아보겠습니다. filter(_:) Returns an array containing, in order, the elements of the sequence that satisfy the given predicate. Declaration func filter(_ isIncluded: (Self.Element) throws -> Bool) rethrows -> [Self.Element] Parameters isIncluded A closure that takes an element of the sequence as its argument and returns a Boolean value indicating whe..

<Map> 함수 더하기 추론<조금>, <compactMap>, <flatMap>

안녕하세요. KataRN입니다. 오늘은 함수 Map에 대해 정리해보려고합니다. 제가 프로그래머스 1단계를 쭉 풀면서 다른사람들이 푼 내용과 비교도 해봤는데 map, reduce, filter 이 3가지를 쓴 풀이들이 코드가 깔끔합니다. 그리고 추론을 하면 할 수록 코드는 더 간결해지죠.(단 상대적으로 효율성은 떨어지더라구요...) 문제는 코드가 간결한 만큼 읽는 순간 이해가 빠르게 되느냐인데 제가 추론에 약해서인지 처음엔 힘들었습니다. 그래서 이번 기회에 3가지 함수에 대해 정리를 하고 응용도 해보겠습니다. 우선 공식문서를 통해 알아보도록 하죠. map(_:) Returns an array containing the results of mapping the given closure over the seq..

반응형