status

xduce.util. status

Source:

Helper functions for writing transducers. These are markers for telling the transducer engine that operation on a value should be complete, even if there are still input elements left.

For example, the take transducer marks its output collection as completed when it takes a certain number of items. This allows reduction to be shut off before all of the elements of the input collection are processed.

Without being able to be marked as completed, the only other option for the take transducer would be to process the collection to its end and simply not add any of the elements after a certain number to the output collection. This would be inefficient and would also make it impossible for take to handle infinite iterators.

Values can be completed multiple times. This nests a completed value inside a completed value, and so on. To uncomplete values like this, uncomplete would have to be called multiple times. This is used in the library in the flatten transducer.

Methods

(static) complete(value) → {*}

Source:

Marks a value as complete.

This is done by wrapping the value. This means three things: first, a complete object may be marked as complete again; second, a complete value isn't usable without being uncompleted first; and third any type of value (including undefined) may be marked as complete.

Parameters:
Name Type Description
value *

The value to be completed.

Returns:

A completed version of the provided value. This reduction is achieved by wrapping the value in a marker object.

Type
*

(static) ensureCompleted(value) → {*}

Source:

Makes sure that a value is marked as complete; if it is not, it will be marked as complete.

This differs from complete in that if the value is already complete, this function won't complete it again. Therefore thus function can't be used to make a value complete multiple times.

Parameters:
Name Type Description
value *

The value to be completed.

Returns:

If the value is already complete, then the value is simply returned. Otherwise, a completed version of the value is returned.

Type
*

(static) ensureUncompleted(value) → {*}

Source:

Removes the complete status from a value, as long as it actually is complete.

This does a check to make sure the value passed in actually is complete. If it isn't, the value itself is returned. It's meant to be used when the completed status is uncertain.

Parameters:
Name Type Description
value *

The complete value to be uncompleted.

Returns:

If the value is already uncompleted, the value is simply returned. Otherwise an uncompleted version of the value is returned.

Type
*

(static) isCompleted(value) → {boolean}

Source:

Determines whether a value is marked as complete.

Parameters:
Name Type Description
value *

The value to test for its complete status.

Returns:

Either true if the value is complete, or false if it is not.

Type
boolean

(static) uncomplete(value) → {*}

Source:

Removes the complete status from a completed value.

This function is intended to be used when it's certain that a value is already marked as complete. If it is not, undefined will be returned instead of the value.

Parameters:
Name Type Description
value *

The value to be uncompleted.

Returns:

An uncompleted version of the provided value. If the value was not complete in the first place, undefined will be returned instead.

Type
*