Array Observable
Rocket.from
— Functionfrom(x; scheduler::H = AsapScheduler()) where { H <: AbstractScheduler }
from(a::Vector{D}; scheduler::H = AsapScheduler()) where { D, H <: AbstractScheduler }
Creation operator for the ArrayObservable
that emits either a single value if x has a Scalar
trait specification or a collection of values if x has a NonScalar
trait specification. Throws an ErrorException if x has UndefinedScalarness
trait type. To specify scalarness for arbitrary type T some can implement an additional method for scalarness(::Type{<:MyType})
function and to specify scalarness behavior. Optionally accepts custom scheduler-like object to schedule messages delivery.
Arguments
x
: an object to be wrapped into array of valuesscheduler
: optional, scheduler-like object
For an object x
to be a valid input for a from operator it must implement Rocket.scalarness(::Type{ <: T })
method which should return either Rocket.Scalar
or Rocket.NonScalar
objects. In first case from
operator will treat x
as a single scalar value and will wrap it into a vector while in the second case from
operator will convert x
object into an array using collect
function.
For arbitrary iterable objects consider using iterable
creation operator.
Note
from
operators creates a copy of x
using collect
on a given object.
Examples
using Rocket
source = from([ 0, 1, 2 ])
subscribe!(source, logger())
;
# output
[LogActor] Data: 0
[LogActor] Data: 1
[LogActor] Data: 2
[LogActor] Completed
using Rocket
source = from(( 0, 1, 2 ))
subscribe!(source, logger())
;
# output
[LogActor] Data: 0
[LogActor] Data: 1
[LogActor] Data: 2
[LogActor] Completed
using Rocket
source = from(0)
subscribe!(source, logger())
;
# output
[LogActor] Data: 0
[LogActor] Completed
using Rocket
source = from("Hello, world!")
subscribe!(source, logger())
;
# output
[LogActor] Data: H
[LogActor] Data: e
[LogActor] Data: l
[LogActor] Data: l
[LogActor] Data: o
[LogActor] Data: ,
[LogActor] Data:
[LogActor] Data: w
[LogActor] Data: o
[LogActor] Data: r
[LogActor] Data: l
[LogActor] Data: d
[LogActor] Data: !
[LogActor] Completed
See also: ArrayObservable
, subscribe!
, logger
, iterable
Rocket.ArrayObservable
— TypeArrayObservable{D, H}(values::Vector{D}, scheduler::H) where { D, H }
ArrayObservable wraps a regular Julia array into an observable. Uses scheduler object to schedule messages delivery.
Constructor arguments
values
: array of values to be wrappedscheduler
: Scheduler-like object
See also: Subscribable
, from