let 취침모드 = PublishSubject<String>()
취침모드
.ignoreElements()
.subscribe{_ in
print("햇빛")
}
.disposed(by: disposeBag)
취침모드.onNext("기상")
취침모드.onNext("기상")
취침모드.onNext("기상")
//출력
//(아무것도 출력되지 않음)
let disposeBag = DisposeBag()
let 두번울면깨는사람 = PublishSubject<String>()
두번울면깨는사람
.element(at: 2)
.subscribe(
onNext:{
print($0)
})
.disposed(by: disposeBag)
두번울면깨는사람.onNext("기상0") //index 0
두번울면깨는사람.onNext("기상1") //index 1
두번울면깨는사람.onNext("기상2") //index 2
두번울면깨는사람.onNext("기상3") //index 3
//출력
//기상2
let disposeBag = DisposeBag()
Observable.of(1,2,3,4,5,6,7,8,9)
.filter{ num in
num % 2 == 0
}
.subscribe(
onNext:{
print($0)
}).disposed(by: disposeBag)
//출력
//2 4 6 8
Observable.of(1,2,3,4,5,6,7,8,9)
.skip(3)
.subscribe(
onNext:{
print($0)
}).disposed(by: disposeBag)
//출력
// 4 5 6 7 8 9
let disposeBag = DisposeBag()
Observable.of(1,2,3,4,5,6,7,8,9)
.skip(while: {
$0 != 6
})
.subscribe(
onNext:{
print($0)
})
.disposed(by: disposeBag)
//출력
//6 7 8 9
let disposeBag = DisposeBag()
let 손님 = PublishSubject<String>()
let 문여는시간 = PublishSubject<String>()
손님
.skip(until: 문여는시간)
.subscribe(onNext: {
print($0)
})
.disposed(by: disposeBag)
손님.onNext("1")
손님.onNext("2")
문여는시간.onNext("시작")
손님.onNext("3")
//출력
//3
let disposeBag = DisposeBag()
Observable.of("A","B","C","D","E")
.enumerated()
.take(while: {index,_ in
index != 3
}).subscribe(onNext:{
print($0)
}).disposed(by: disposeBag)
//출력
//(index: 0, element: "A")
//(index: 1, element: "B")
//(index: 2, element: "C")
→ 바꿔주는 연산자
→ 결합 연산자