rx

package
v0.0.0-...-5993f49 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package rx provides an example of using Reactive Extensions (ReactiveX) for Go.

Example (Generic)

Use the generics from package "github.com/reactivego/rx" and generate function FromString and method MapString and Println by running the jig command.

FromString("You!", "Gophers!", "World!").
	MapString(func(x string) string {
		return "Hello, " + x
	}).
	Println()
Output:

Hello, You!
Hello, Gophers!
Hello, World!
Example (Heterogeneous)

Use the implementations from package "github.com/reactivego/rx" directly. The rx package at the root of the library contains all generics expanded for the interface{} type.

type any = interface{}

rx.From("You!", "Gophers!", "World!").
	Map(func(x any) any {
		return "Hello, " + x.(string)
	}).
	Println()
Output:

Hello, You!
Hello, Gophers!
Hello, World!

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ObservableString

type ObservableString func(StringObserveFunc, Scheduler, Subscriber)

ObservableString is essentially a subscribe function taking an observe function, scheduler and an subscriber.

func FromSliceString

func FromSliceString(slice []string) ObservableString

FromSliceString creates an ObservableString from a slice of string values passed in.

func FromString

func FromString(slice ...string) ObservableString

FromString creates an ObservableString from multiple string values passed in.

func (ObservableString) MapString

func (o ObservableString) MapString(project func(string) string) ObservableString

MapString transforms the items emitted by an ObservableString by applying a function to each item.

func (ObservableString) Println

func (o ObservableString) Println() (err error)

Println subscribes to the Observable and prints every item to os.Stdout while it waits for completion or error. Returns either the error or nil when the Observable completed normally. Println is performed on the Trampoline scheduler.

type Scheduler

type Scheduler scheduler.Scheduler

Scheduler is used to schedule tasks to support subscribing and observing.

func GoroutineScheduler

func GoroutineScheduler() Scheduler

func TrampolineScheduler

func TrampolineScheduler() Scheduler

type StringObserveFunc

type StringObserveFunc func(next string, err error, done bool)

StringObserveFunc is the observer, a function that gets called whenever the observable has something to report. The next argument is the item value that is only valid when the done argument is false. When done is true and the err argument is not nil, then the observable has terminated with an error. When done is true and the err argument is nil, then the observable has completed normally.

type Subscriber

type Subscriber subscriber.Subscriber

Subscriber is an alias for the subscriber.Subscriber interface type.

func NewSubscriber

func NewSubscriber() Subscriber

NewSubscriber creates a new subscriber.

type Subscription

type Subscription subscriber.Subscription

Subscription is an alias for the subscriber.Subscription interface type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL