✨
Combine 🀝 RxSwift 🀝 ReactiveSwift
  • Combine 🀝 RxSwift 🀝 ReactiveSwift
  • Publisher
    • Publishers.Merge
    • Publishers.Zip3
    • Publishers.TryScan
    • Publishers.MergeMany
    • Publishers.Breakpoint
    • AnyPublisher
    • Publishers.Concatenate
    • Publishers.Drop
    • Publishers.Decode
    • Publishers.TryCompactMap
    • Publishers.CombineLatest4
    • Optional.Publisher
    • Publishers.CollectByCount
    • Publishers.TryFilter
    • Publishers.CombineLatest3
    • Publishers.TryContainsWhere
    • Just
    • Publishers.TryFirstWhere
    • Publishers.MapError
    • Publishers.RemoveDuplicates
    • Result.Publisher
    • Publishers.LastWhere
    • Publishers.First
    • Publishers.Throttle
    • Publishers.DropUntilOutput
    • Publishers.Count
    • Publishers.Comparison
    • Publishers.Debounce
    • Publishers.MapKeyPath
    • Publishers.CollectByTime
    • Publishers.TryDropWhile
    • Empty
    • Publishers.PrefixUntilOutput
    • Publishers.Print
    • URLSession.DataTaskPublisher
    • Publishers.Reduce
    • Publishers.MapKeyPath3
    • Publishers.Collect
    • Publishers.TryPrefixWhile
    • Publishers.MapKeyPath2
    • Future
    • Publishers.SubscribeOn
    • Publishers.AllSatisfy
    • Publishers.Retry
    • Publishers.ContainsWhere
    • Publishers.SetFailureType
    • Publishers.TryMap
    • Publishers.Output
    • Publishers.TryRemoveDuplicates
    • Publishers.HandleEvents
    • Publishers.Sequence
    • Publishers.TryCatch
    • Publishers.Merge8
    • Publishers.CombineLatest
    • Deferred
    • Publishers.Merge7
    • Publishers.Contains
    • Fail
    • Publishers.Merge6
    • Publishers.TryComparison
    • Publishers.Delay
    • Publishers.Scan
    • Publishers.Merge5
    • Publishers.MeasureInterval
    • Publishers.AssertNoFailure
    • Publishers.ReceiveOn
    • Publishers.Merge4
    • Publishers.DropWhile
    • Publishers.Merge3
    • Publishers.TryReduce
    • Publishers.Zip
    • Publishers.Timeout
    • Publishers.CompactMap
    • Publishers.ReplaceEmpty
    • Publishers.PrefixWhile
    • Publishers.Filter
    • Publishers.TryAllSatisfy
    • Publishers.FirstWhere
    • Publishers.Last
    • Publishers.Map
    • Publishers.SwitchToLatest
    • Publishers.TryLastWhere
    • Publishers.Encode
    • Publishers.Catch
    • Publishers.ReplaceError
    • Pulishers.IgnoreOutput
    • Publishers.Zip4
  • Subject
    • PassthroughSubject
    • CurrentValueSubject
  • Subscriber
Powered by GitBook
On this page
  • RxSwift
  • ReactiveSwift

Was this helpful?

  1. Publisher

Publishers.LastWhere

μ œλ„€λ¦­ ꡬ쑰체 | 슀트림이 μ’…λ£Œν•˜λ©΄, νŠΉμ • 쑰건 ν΄λ‘œμ €λ₯Ό λ§Œμ‘±ν•˜κΈ° μœ„ν•œ 슀트림의 λ§ˆμ§€λ§‰ μš”μ†Œλ§Œμ„ λ°œν–‰ν•˜λŠ” Publisher

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

  • upstream : μƒμœ„μ— 흐λ₯΄λŠ” Publisher

  • predicate : μ–΄λ–€ μš”μ†Œλ₯Ό λ°œν–‰ν• μ§€ κ²°μ •ν•˜λŠ” ν΄λ‘œμ €

μƒμœ„ Publisherλ‘œλΆ€ν„° 쑰건 ν΄λ‘œμ €μ— λ§Œμ‘±ν•˜λŠ” μš”μ†Œλ₯Ό λ¨Όμ € 뽑아내고, κ·Έ μ€‘μ—μ„œ λ§ˆμ§€λ§‰ μš”μ†Œλ§Œμ„ λ°œν–‰ν•œλ‹€.

last μ˜€νΌλ ˆμ΄ν„°μ™€ 관련이 μžˆλ‹€.

// Publishers.LastWhere Publisher
Publishers
  .LastWhere(upstream: Publishers.Sequence<[Int], Never>(sequence: [1, 2, 3, 4, 5])) { !$0.isMultiple(of: 2) }
  .sink(receiveCompletion: { completion in
    switch completion {
    case .failure:
      print("Combine FirstWhere Error")
    case .finished:
      print("Combine FirstWhere Finish")
    }
  }, receiveValue: { value in
    print("Combine FirstWhere : \(value)")
  })
  .store(in: &cancellables)

// last Operator
Publishers.Sequence<[Int], Never>(sequence: [1, 2, 3, 4, 5])
  .last { !$0.isMultiple(of: 2) }
  .sink(receiveCompletion: { completion in
    switch completion {
    case .failure:
      print("Combine FirstWhere Error")
    case .finished:
      print("Combine FirstWhere Finish")
    }
  }, receiveValue: { value in
    print("Combine FirstWhere : \(value)")
  })
  .store(in: &cancellables)

// Combine LastWhere : 5
// Combine LastWhere Finish

μƒμœ„ PublisherλŠ” 1, 2, 3, 4, 5의 값을 μ°¨λ‘€λŒ€λ‘œ λ‚΄κ³ , 2의 λ°°μˆ˜κ°€ μ•„λ‹Œ 쑰건을 μ„€μ •ν–ˆλ‹€.

κ°’λ“€ 쀑 2의 λ°°μˆ˜κ°€ μ•„λ‹Œ 1, 3, 5 쀑 λ§ˆμ§€λ§‰ μš”μ†ŒλŠ” 5μ΄λ―€λ‘œ, μ΅œμ’…μ μœΌλ‘œ 5의 값을 λ‚΄κ³  μ’…λ£Œν•œλ‹€.

RxSwift

ν•΄λ‹Ή λ™μž‘μ„ κ΅¬ν˜„ν•˜κΈ° μœ„ν•œ μ˜€νΌλ ˆμ΄ν„°λ₯Ό μ œκ³΅ν•˜μ§€ μ•ŠλŠ”λ‹€.

ReactiveSwift

ν•΄λ‹Ή λ™μž‘μ„ κ΅¬ν˜„ν•˜κΈ° μœ„ν•œ μ˜€νΌλ ˆμ΄ν„°λ₯Ό μ œκ³΅ν•˜μ§€ μ•ŠλŠ”λ‹€.

PreviousResult.PublisherNextPublishers.First

Last updated 5 years ago

Was this helpful?