The next figure shows how to create a sequence by emitting only the first element emitted by a source Observable sequence:
The first()
and last()
methods are quite easy to figure out. They emit only the first or last element emitted by Observable. Both of them can even get Func1
as a parameter: a predicate that can be used to decide the actual first or last element we are interested in.
The next figure shows how last()
can be applied to a completed sequence to create a new Observable that emits only the last emitted element:
Both first()
and last()
come with a similar variant: firstOrDefault()
and lastOrDefault()
. These two functions come in handy when the Observable sequence completes without emitting any value. In this scenario, we can decide a default value to emit if the Observable didn't emit any.
18.117.230.81