μ λ€λ¦ ꡬ쑰체 | λ€λ₯Έ Publisherκ° μμλ₯Ό λ°©μΆνκΈ° μ΄μ μ ν Publisherμ μμλ₯Ό λͺ¨λ λ°©μΆνλ Publisher
μ΄λμ
λΌμ΄μ λ λ κ°μ μΈμλ₯Ό λ°λλ€.
prefix : suffixκ° μμλ₯Ό λ€μ λ°ννκΈ° μ΄μ μ λͺ¨λ μμλ₯Ό λ€μ λ°ννλ Publisher
suffix : prefix Publisherκ° μ’
λ£ν μ§ν λ€μ λ°ννλ Publisher
prefix Publisherμ suffix Publisherμ Output νμ
κ³Ό μλ¬ νμ
μ λμΌν΄μΌ νλ€.
Publisherλ₯Ό μ΄μ΄ λΆμ΄κ±°λ μμλ₯Ό μΆκ°ν λ μ¬μ©ν μ μλ€.
append λ° prepend μ€νΌλ μ΄ν°μ κ΄λ ¨μ΄ μλ€.
append μ€νΌλ μ΄ν°λ λ€μμ ννλ₯Ό κ°λλ€.
κ°λ³ μΈμλ₯Ό λ°μ κΈ°μ‘΄ Publisherκ° μ’
λ£ν ν μ΄μ΄μ λ°ννλ€. ex) Just(1).append(2, 3)
μνμ€λ₯Ό λ°μ κΈ°μ‘΄ Publisherκ° μ’
λ£ν ν μ΄μ΄μ λ°ννλ€. ex) Just(1).append([2, 3])
Publisherλ₯Ό λ°μ κΈ°μ‘΄ Publisherκ° μ’
λ£ν ν μ΄μ΄μ λ°ννλ€. ex) Just(1).append(Just(2))
prepend μ€νΌλ μ΄ν°λ λ€μμ ννλ₯Ό κ°λλ€.
κ°λ³ μΈμλ₯Ό λ°μ κΈ°μ‘΄ Publisherμ μμ μ΄μ΄ λΆμ¬ λ°ννλ€. ex) Just(1).prepend(2, 3)
μνμ€λ₯Ό λ°μ κΈ°μ‘΄ Publisherμ μμ μ΄μ΄ λΆμ¬ λ°ννλ€. ex) Just(1).prepend([2, 3])
Publisherλ₯Ό λ°μ κΈ°μ‘΄ Publisherμ μμ μ΄μ΄ λΆμ¬ λ°ννλ€. ex) Just(1).prepend(Just(2))
// Publishers.Concatenate Publisher
Publishers
.Concatenate(prefix: Just(1), suffix: Just(2))
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Concatenate Error")
case .finished:
print("Combine Concatenate Finish")
}
}, receiveValue: { value in
print("Combine Concatenate : \(value)")
})
.store(in: &cancellables)
// append Operator
Just(1)
.append(Just(2))
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Concatenate Error")
case .finished:
print("Combine Concatenate Finish")
}
}, receiveValue: { value in
print("Combine Concatenate : \(value)")
})
.store(in: &cancellables)
// Combine Concatenate : 1
// Combine Concatenate : 2
// Combine Concatenate Finish
// prepend Operator
Just(1)
.prepend(Just(2))
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Concatenate Error")
case .finished:
print("Combine Concatenate Finish")
}
}, receiveValue: { value in
print("Combine Concatenate : \(value)")
})
.store(in: &cancellables)
// Combine Concatenate : 2
// Combine Concatenate : 1
// Combine Concatenate Finish
1λ² μ½λμ 2λ² μ½λμ κ²½μ° 1μ κ°μ λ΄λ Just Publisherμ λμ 2μ κ°μ λ΄λ Just Publisherλ₯Ό μ΄μ΄ λΆμλ€. κ²°κ³Όμ μΌλ‘ 1κ³Ό 2μ κ°μ μ°¨λ‘λλ‘ λ΄κ³ μ’
λ£νλ€.
3λ² μ½λμ κ²½μ° 1μ κ°μ λ΄λ Just Publisherμ μμ 2μ κ°μ λ΄λ Just Publisherλ₯Ό μ΄μ΄ λΆμλ€. κ²°κ³Όμ μΌλ‘ 2μ 1μ κ°μ μ°¨λ‘λλ‘ λ΄κ³ μ’
λ£νλ€.
concat μ€νΌλ μ΄ν°λ₯Ό μ¬μ©νμ¬ append μ€νΌλ μ΄ν°μ κΈ°λ₯μ ꡬνν μ μλ€.
startWith μ€νΌλ μ΄ν°λ₯Ό μ¬μ©νμ¬ prepend μ€νΌλ μ΄ν°μ κΈ°λ₯μ ꡬνν μ μλ€.
concat μ€νΌλ μ΄ν°λ₯Ό μ¬μ©νμ¬ append μ€νΌλ μ΄ν°μ κΈ°λ₯μ ꡬνν μ μλ€.
prefix μ€νΌλ μ΄ν°λ₯Ό μ¬μ©νμ¬ prepend μ€νΌλ μ΄ν°μ κΈ°λ₯μ ꡬνν μ μλ€.
ReactiveX - Operators - StartWith