event

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package event implements the Event type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func After

func After[A any](dur time.Duration, a A) warp.Event[A]

After creates an event which emits a value after waiting for the specified duration.

func Alt

func Alt[A any](x warp.Event[A], y warp.Event[A]) warp.Event[A]

Alt creates an event which emits values simultaneously from two source events.

func Ap

func Ap[A, B any](fab warp.Event[func(A) B], fa warp.Event[A]) warp.Event[B]

Ap creates an event by applying the latest observed function from the first event on each value received from the second event.

func Chain

func Chain[A, B any](fa warp.Event[A], f func(A) warp.Event[B]) warp.Event[B]

Chain creates an event which composes two events in sequence, using the return value of the first event to determine the next one.

func Count

func Count[A any](fa warp.Event[A]) warp.Event[int]

Count creates an event that emits the number of times a source event is fired.

func CountAll

func CountAll[A any](ctx context.Context, fa warp.Event[A]) int

CountAll returns the number of times a source event is fired in total.

func Empty

func Empty() warp.Event[struct{}]

Empty creates an event which emits an empty struct forever.

func Filter

func Filter[A any](fa warp.Event[A], predicate warp.Predicate[A]) warp.Event[A]

Filter creates an event which emits values from a source event when a predicate holds.

func FilterMap

func FilterMap[A, B any](fa warp.Event[A], f func(a A) warp.Nilable[B]) warp.Event[B]

func Fold

func Fold[A, B any](fa warp.Event[A], b B, f func(A, B) B) warp.Event[B]

Fold creates an event which combines the values from a source event by applying a function starting with an initial value.

func From

func From[A any](as []A) warp.Event[A]

From creates an event which emits multiple values sequentially from the supplied slice.

func FromChannel

func FromChannel[A any](source <-chan A) warp.Event[A]

func FromIO

func FromIO[A any](io warp.IO[A]) warp.Event[A]

func Interval

func Interval(dur time.Duration) warp.Event[time.Time]

Interval creates an event which emits the current time periodically.

func Map

func Map[A, B any](fa warp.Event[A], f func(A) B) warp.Event[B]

Map creates an event by applying a function on each value received from a source event.

func MapNotNil

func MapNotNil[A, B any](fa warp.Event[A], f func(A) *B) warp.Event[B]

MapNotNil creates an event which filters out any nil values by applying a function on each value received from some source event.

func Of

func Of[A any](a A) warp.Event[A]

Of creates an event which emits a single value.

func Once

func Once[A any](fa warp.Event[A], predicate warp.Predicate[A]) warp.Event[A]

Once creates an event which emits values from an event for once and the last time when a predicate holds.

func Reduce

func Reduce[A, B any](ctx context.Context, fa warp.Event[A], b B, f func(B, A) B) B

Reduce returns a value by applying a function on each value received from an event, in order, passing in the value and the return value from the calculation on the preceding element.

func ReduceRight

func ReduceRight[A, B any](ctx context.Context, fa warp.Event[A], b B, f func(A, B) B) B

ReduceRight applies a function against an accumulator and each observed value of the event (from right-to-left) to reduce it to a single value. Same as Reduce but applied from end to start.

func SampleOn

func SampleOn[A, B any](fa warp.Event[A], fab warp.Event[func(A) B]) warp.Event[B]

SampleOn creates an event which samples the latest values from the first event at the times when the second event fires.

func SampleOn_

func SampleOn_[A, B any](fa warp.Event[A], fb warp.Event[B]) warp.Event[A]

SampleOn_ creates an event which samples the latest values from the first event at the times when the second event fires, ignoring the values produced by the second event.

func Take

func Take[A any](fa warp.Event[A], n int) warp.Event[A]

Take creates an event which emits the first n values observed from a source event.

func Until

func Until[A any](fa warp.Event[A], predicate warp.Predicate[A]) warp.Event[A]

Until creates an event which emits values from an event until a predicate holds.

func WithLast

func WithLast[A any](fa warp.Event[A]) warp.Event[Last[A]]

WithLast creates an event which emits successive event values.

func WithTime

func WithTime[A any](fa warp.Event[A]) warp.Event[Time[A]]

WithTime creates an event which reports the current local time.

Types

type Last

type Last[A any] struct {
	Now  A
	Last A
}

A Last represents an event associated with its last value.

type Time

type Time[A any] struct {
	Value A
	Time  time.Time
}

A Time represents an event value associated with some time.

Jump to

Keyboard shortcuts

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