rxSwift Flashcards

1
Q

What is side effects?

A

Side effects are any change to the state outside of the current scope.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Imperative programming?

A

Imperative programming is a programming paradigm that uses statements to change the program’s state.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Core issues that rxSwift dealt with

A

Shared mutable data
The order in which pieces of work are performed

“RxSwift finds the sweet spot between traditionally imperative Cocoa code and purist functional code. It allows you to react to events by using immutable code definitions to process asynchronously pieces of input in a deterministic, composable way.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Subject in RxSwift

A

Observable and Observer

Publish/Behaviour/Replay

Replay:
To kill cache you have to call dispose
“buffer is held in memory.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What subject do after termination?

A

Every subject type, once terminated, will re-emit its stop event to future subscribers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Creating observable factories

A

Observable.deferred { }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain Observables

A

“Carry” an immutable piece of data Observable

Traits
Single
Maybe
Completable

Events
Next
Completed
Error

an observable won’t send events until it has a subscriber. Remember that an observable is really a sequence definition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Filtering operators -> Ignoring operators

A

ignoreElements()
elementAt(1)
filter { $0 > 3 }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Filtering operators -> skiping operators

A

skip(2)
skipWhile { $0 % 2 == 1}
skipUntil - hasTrigger

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Filtering operators -> taking operators

A

takeWhile { $0 < 3 }
take(2)
takeUntil - has trigger
elementAt(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Filtering operators -> Distinct operators

A

DistinctUntilChanged {$0 $1}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Filtering operators -> Transforming operators

A
toArray 
map -> can be .enumerated()
flatMap
flatMapLatest 
Materialize
Dematerialise
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Explain flatMap and flatMapLatest

A

Add async and project observable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Combining operators

A
Combining operators
	Start with
	concat: sequential processing. concat
	concatMap
	merge: Just one event from observable that sends it event (can be many observables )
	cobineLatest: Combine events from observables and sends it together
	triggers
		withLatestFrom
		sample
	switches
		amb
		SwitchLatest
	reduce
	scan
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Timing operators

A
Timing operators
	Replaying past elements: You should call .connect() to start
		ReplayAll
		.replay(amount)
	Controlled buffering -> The only difference is that it emits an Observable of the buffered items, instead of emitting an array.
		.buffer(timeSpan:count:scheduler:)
	Windows of buffered observables
		.window(timeSpan:, count:, scheduler:)
	Time-shifting operators
		Delayed elements
		Delayed subscription
		Timer operators
			Intervals
			One-shot or repeating timers
			Timeouts

.take(5.0, scheduler: MainScheduler.instance)
.throttle(0.5, scheduler: MainScheduler.instance)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Cold vs hot observables

A

“Note: In Rx, some observables are called “cold” while others are “hot”. Cold observables start emitting elements when you subscribe to them. Hot observables are more like permanent sources you happen to look at at some point (think of Notifications). When delaying a subscription, it won’t make a difference if the observable is cold. If it’s hot, you may skip elements, as in this example.
Hot and cold observables are a tricky topic that can take some time getting your head around. Remember that cold observables emit events only when subscribed to, but hot observables emit events independent of being subscribed to.”

Excerpt From: By Marin Todorov. “RxSwift - Reactive Programming with Swift”. Apple Books.

17
Q

Sharing

A

“To share a subscription, you can use the share() operator. A common pattern in Rx code is to create several sequences from the same source Observable by filtering out different elements in each of the results.”

share vs shareReplay