CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-rx

Library for composing asynchronous and event-based operations in JavaScript using Observable sequences and fluent query operators

Pending
Overview
Eval results
Files

observable-filtering.mddocs/

Observable Filtering

Operators for filtering observable sequences including filter, take, skip, distinct, and debounce operations.

Capabilities

Filter/Where

Filters elements based on a predicate function.

/**
 * Filters elements based on a predicate function
 * @param {function} predicate - Function to test each element
 * @param {*} [thisArg] - Object to use as this when executing predicate
 * @returns {Observable} Observable sequence containing filtered elements
 */
observable.filter = function(predicate, thisArg);
observable.where = function(predicate, thisArg); // Alias for filter

Usage Example:

var source = Rx.Observable.range(1, 10);
var evens = source.filter(function(x) { return x % 2 === 0; });
// Emits: 2, 4, 6, 8, 10

Take

Takes the first specified number of elements.

/**
 * Takes the first count elements from an observable sequence
 * @param {number} count - Number of elements to take
 * @param {Scheduler} [scheduler] - Scheduler to use for the subscription
 * @returns {Observable} Observable sequence containing the first count elements
 */
observable.take = function(count, scheduler);

Take While

Takes elements while a predicate is true.

/**
 * Takes elements from start of sequence while predicate is true
 * @param {function} predicate - Function to test each element
 * @param {*} [thisArg] - Object to use as this when executing predicate
 * @returns {Observable} Observable sequence containing elements while predicate is true
 */
observable.takeWhile = function(predicate, thisArg);

Take Last

Takes the last specified number of elements.

/**
 * Takes the last count elements from an observable sequence
 * @param {number} count - Number of elements to take from the end
 * @returns {Observable} Observable sequence containing the last count elements
 */
observable.takeLast = function(count);

Take Last Buffer

Takes the last elements and returns them as an array.

/**
 * Takes the last count elements and returns them as a single array
 * @param {number} count - Number of elements to take from the end
 * @returns {Observable} Observable sequence containing array of last count elements
 */
observable.takeLastBuffer = function(count);

Take Until

Takes elements until another observable emits.

/**
 * Takes elements until the other observable sequence emits a value
 * @param {Observable} other - Observable sequence that terminates propagation
 * @returns {Observable} Observable sequence taking elements until other emits
 */
observable.takeUntil = function(other);

Usage Example:

var source = Rx.Observable.interval(100);
var stopSignal = Rx.Observable.timer(500);
var result = source.takeUntil(stopSignal);
// Emits: 0, 1, 2, 3, 4 (stops after 500ms)

Skip

Skips the first specified number of elements.

/**
 * Skips the first count elements from an observable sequence
 * @param {number} count - Number of elements to skip
 * @returns {Observable} Observable sequence skipping the first count elements
 */
observable.skip = function(count);

Skip While

Skips elements while a predicate is true.

/**
 * Skips elements from start of sequence while predicate is true
 * @param {function} predicate - Function to test each element
 * @param {*} [thisArg] - Object to use as this when executing predicate
 * @returns {Observable} Observable sequence skipping elements while predicate is true
 */
observable.skipWhile = function(predicate, thisArg);

Skip Last

Skips the last specified number of elements.

/**
 * Skips the last count elements from an observable sequence
 * @param {number} count - Number of elements to skip from the end
 * @returns {Observable} Observable sequence skipping the last count elements
 */
observable.skipLast = function(count);

Skip Until

Skips elements until another observable emits.

/**
 * Skips elements until the other observable sequence emits a value
 * @param {Observable} other - Observable sequence that starts propagation
 * @returns {Observable} Observable sequence skipping elements until other emits
 */
observable.skipUntil = function(other);

Distinct

Filters out duplicate values from the sequence.

/**
 * Returns distinct elements from an observable sequence
 * @param {function} [keySelector] - Function to compute comparison key for each element
 * @param {function} [comparer] - Function to compare keys for equality
 * @returns {Observable} Observable sequence containing distinct elements
 */
observable.distinct = function(keySelector, comparer);

Usage Example:

var source = Rx.Observable.fromArray([1, 2, 2, 3, 1, 4]);
var distinct = source.distinct();
// Emits: 1, 2, 3, 4

Distinct Until Changed

Filters out consecutive duplicate values.

/**
 * Returns distinct contiguous elements from an observable sequence
 * @param {function} [keySelector] - Function to compute comparison key for each element
 * @param {function} [comparer] - Function to compare keys for equality
 * @returns {Observable} Observable sequence with consecutive duplicates removed
 */
observable.distinctUntilChanged = function(keySelector, comparer);

Usage Example:

var source = Rx.Observable.fromArray([1, 1, 2, 2, 2, 3, 3, 1]);
var distinct = source.distinctUntilChanged();
// Emits: 1, 2, 3, 1

Ignore Elements

Ignores all elements and only propagates completion or error.

/**
 * Ignores all elements in an observable sequence leaving only termination messages
 * @returns {Observable} Observable sequence with all elements ignored
 */
observable.ignoreElements = function();

Default If Empty

Provides a default value if the sequence is empty.

/**
 * Returns elements from sequence, or default value if sequence is empty
 * @param {*} [defaultValue] - Default value to return if sequence is empty
 * @returns {Observable} Observable sequence with default value if empty
 */
observable.defaultIfEmpty = function(defaultValue);

Usage Example:

var empty = Rx.Observable.empty();
var withDefault = empty.defaultIfEmpty('No data');
// Emits: 'No data'

Element At

Returns the element at a specified index.

/**
 * Returns the element at the specified index in the sequence
 * @param {number} index - Zero-based index of element to retrieve
 * @returns {Observable} Observable sequence containing element at specified index
 */
observable.elementAt = function(index);

Element At Or Default

Returns the element at a specified index or a default value.

/**
 * Returns element at specified index or default value if index is out of range
 * @param {number} index - Zero-based index of element to retrieve
 * @param {*} [defaultValue] - Default value if index is out of range
 * @returns {Observable} Observable sequence containing element or default value
 */
observable.elementAtOrDefault = function(index, defaultValue);

Single

Returns the only element of a sequence or throws an error.

/**
 * Returns the only element of a sequence, or throws error if not exactly one element
 * @param {function} [predicate] - Function to test each element
 * @param {*} [thisArg] - Object to use as this when executing predicate
 * @returns {Observable} Observable sequence containing the single element
 */
observable.single = function(predicate, thisArg);

Single Or Default

Returns the only element of a sequence or a default value.

/**
 * Returns the only element of a sequence or default value
 * @param {function} [predicate] - Function to test each element
 * @param {*} [defaultValue] - Default value if no element or more than one element
 * @param {*} [thisArg] - Object to use as this when executing predicate
 * @returns {Observable} Observable sequence containing the single element or default
 */
observable.singleOrDefault = function(predicate, defaultValue, thisArg);

Find

Searches for an element that matches the conditions and returns the first occurrence.

/**
 * Searches for an element that matches the conditions and returns the first occurrence
 * @param {function} predicate - Function to test each element
 * @param {*} [thisArg] - Object to use as this when executing predicate
 * @returns {Observable} Observable sequence containing the first matching element or undefined
 */
observable.find = function(predicate, thisArg);

FindIndex

Searches for an element that matches the conditions and returns the index.

/**
 * Searches for an element that matches the conditions and returns the zero-based index
 * @param {function} predicate - Function to test each element
 * @param {*} [thisArg] - Object to use as this when executing predicate
 * @returns {Observable} Observable sequence containing the index or -1 if not found
 */
observable.findIndex = function(predicate, thisArg);

IndexOf

Returns the index of the first occurrence of a value.

/**
 * Returns the index of the first occurrence of a value in the sequence
 * @param {*} searchElement - Element to locate
 * @param {number} [fromIndex] - Index to start the search at
 * @returns {Observable} Observable sequence containing the index or -1 if not found
 */
observable.indexOf = function(searchElement, fromIndex);

LastIndexOf

Returns the index of the last occurrence of a value.

/**
 * Returns the index of the last occurrence of a value in the sequence
 * @param {*} searchElement - Element to locate
 * @param {number} [fromIndex] - Index to start the search at
 * @returns {Observable} Observable sequence containing the index or -1 if not found
 */
observable.lastIndexOf = function(searchElement, fromIndex);

Includes

Determines whether the sequence includes a certain element.

/**
 * Determines whether the sequence includes a certain element
 * @param {*} searchElement - Element to search for
 * @param {number} [fromIndex] - Index to start the search at
 * @returns {Observable} Observable sequence containing boolean result
 */
observable.includes = function(searchElement, fromIndex);

Slice

Returns elements from start index to end index.

/**
 * Returns elements from start index to end index
 * @param {number} start - Zero-based index at which to begin extraction
 * @param {number} [end] - Zero-based index at which to end extraction
 * @returns {Observable} Observable sequence containing sliced elements
 */
observable.slice = function(start, end);

TakeLast

Returns a specified number of contiguous elements from the end.

/**
 * Returns a specified number of contiguous elements from the end of sequence
 * @param {number} count - Number of elements to take from end
 * @returns {Observable} Observable sequence containing the last elements
 */
observable.takeLast = function(count);

SkipLast

Bypasses a specified number of elements at the end.

/**
 * Bypasses a specified number of elements at the end of sequence
 * @param {number} count - Number of elements to skip from end
 * @returns {Observable} Observable sequence bypassing the last elements
 */
observable.skipLast = function(count);

TakeLastBuffer

Returns the last elements as a single array emission.

/**
 * Returns the last elements as a single array emission
 * @param {number} count - Number of elements to take from end
 * @returns {Observable} Observable sequence containing array of last elements
 */
observable.takeLastBuffer = function(count);

TakeLastWithTime

Returns elements within a specified time window from the end.

/**
 * Returns elements within a specified time window from the end
 * @param {number} duration - Maximum time interval between values
 * @param {Scheduler} [scheduler] - Scheduler to run timers on
 * @returns {Observable} Observable sequence containing time-windowed elements
 */
observable.takeLastWithTime = function(duration, scheduler);

SkipLastWithTime

Skips elements within a specified time window from the end.

/**
 * Skips elements within a specified time window from the end
 * @param {number} duration - Maximum time interval between values
 * @param {Scheduler} [scheduler] - Scheduler to run timers on
 * @returns {Observable} Observable sequence skipping time-windowed elements
 */
observable.skipLastWithTime = function(duration, scheduler);

TakeWithTime

Takes elements for the specified duration.

/**
 * Takes elements for the specified duration from the start of sequence
 * @param {number} duration - Duration to take elements for
 * @param {Scheduler} [scheduler] - Scheduler to run timers on
 * @returns {Observable} Observable sequence containing elements within time window
 */
observable.takeWithTime = function(duration, scheduler);

SkipWithTime

Skips elements for the specified duration.

/**
 * Skips elements for the specified duration from the start of sequence
 * @param {number} duration - Duration to skip elements for
 * @param {Scheduler} [scheduler] - Scheduler to run timers on
 * @returns {Observable} Observable sequence skipping elements within time window
 */
observable.skipWithTime = function(duration, scheduler);

Install with Tessl CLI

npx tessl i tessl/npm-rx

docs

async-operations.md

disposables.md

index.md

observable-aggregation.md

observable-combination.md

observable-creation.md

observable-filtering.md

observable-transformation.md

schedulers.md

subjects.md

testing.md

time-operations.md

tile.json