Publishers.Sequence

μ œλ„€λ¦­ ꡬ쑰체 | μš”μ†Œμ˜ 주어진 μ‹œν€€μŠ€λ₯Ό λ°œν–‰ν•˜λŠ” Publisher

μ΄λ‹ˆμ…œλΌμ΄μ €λŠ” ν•œ 개의 인자λ₯Ό λ°›λŠ”λ‹€.

  • sequence : λ°œν–‰ν•  μš”μ†Œκ°€ λ‹΄κΈ΄ μ‹œν€€μŠ€

sequenceλŠ” Sequence ν”„λ‘œν† μ½œμ„ 채택해야 ν•œλ‹€. μ—λŸ¬ νƒ€μž…μ€ Error ν”„λ‘œν† μ½œμ„ 채택해야 ν•œλ‹€.

Publisherκ°€ μ‹œν€€μŠ€μ— μžˆλŠ” μš”μ†Œλ“€μ„ λͺ¨λ‘ μ‚¬μš©ν•˜μ˜€μ„ λ•Œ λ‹€μŒ μš”μ²­μ—μ„œ Publisherκ°€ μ’…λ£Œν•œλ‹€.

μ‹œν€€μŠ€μ— μžˆλŠ” μš”μ†Œλ“€μ„ μ²˜μŒλΆ€ν„° ν•˜λ‚˜ν•˜λ‚˜ λ‚΄λ €μ£Όλ©°, λͺ¨λ“  μš”μ†Œλ₯Ό λ‹€ μ‚¬μš©ν•˜λ©΄ μ’…λ£Œν•œλ‹€.

Publishers.Sequence<[Int], Never>(sequence: [1, 2])
  .sink(receiveCompletion: { completion in
    switch completion {
    case .failure:
      print("Combine Sequence Error")
    case .finished:
      print("Combine Sequence Finish")
    }
  }, receiveValue: {
    print("Combine Sequence : \($0)")
  })
  .store(in: &cancellables)

// Combine Sequence : 1
// Combine Sequence : 2
// Combine Sequence Finish

RxSwift

from μ˜€νΌλ ˆμ΄ν„°λ₯Ό μ‚¬μš©ν•˜μ—¬ κ΅¬ν˜„ν•  수 μžˆλ‹€.

Observable.from([1, 2])
  .subscribe(onNext: {
    print("RxSwift Sequence : \($0)")
  }, onError: { _ in
    print("RxSwift Sequence Error")
  }, onCompleted: {
    print("RxSwift Sequence Finish")
  })
  .disposed(by: disposeBag)

// RxSwift Sequence : 1
// RxSwift Sequence : 2
// RxSwift Sequence Finish

ReactiveSwift

init(_:) μ΄λ‹ˆμ…œλΌμ΄μ €λ₯Ό μ‚¬μš©ν•˜μ—¬ κ΅¬ν˜„ν•  수 μžˆλ‹€.

SignalProducer([1, 2])
  .start { event in
    switch event {
    case let .value(value):
      print("ReactiveSwift Sequence : \(value)")
    case .failed:
      print("ReactiveSwift Sequence Error")
    case .completed:
      print("ReactiveSwift Sequence Finish")
    default:
      break
    }
  }

// ReactiveSwift Sequence : 1
// ReactiveSwift Sequence : 2
// ReactiveSwift Sequence Finish

μ°Έκ³ 

ReactiveX - Operators - From

Last updated