Function annotate

  • Annotates values from source. Output values will be in the form { value: TIn, annotation: TAnnotation }. Where TIn is the type of the input, and TAnnotation is the return type of the annotator function.

    Example calculating area from width & height:

    const data = Rx.From.array(
    { w: 1, h: 3 }, { w: 1, h: 1 }, { w: 2, h: 2 }
    );
    const annotated = Rx.Ops.annotate(data, v => {
    return { area: v.w * v.h }
    });
    const data = await Rx.toArray(annotated);
    // Data = [ { value: { w:1, h:3 }, annotation: { area:3 } } ...]

    If you would rather annotate and have values merge with the input, use transform:

    const data = Rx.From.array(
    { w: 1, h: 3 }, { w: 1, h: 1 }, { w: 2, h: 2 }
    );
    const withArea = Rx.Ops.transform(data, v => {
    return { ...v, area: v.w * v.h }
    });
    const data = await Rx.toArray(withArea);
    // Data = [ { w:1, h:3, area:3 }, ...]

    Type Parameters

    • In
    • TAnnotation

    Parameters

    Returns Reactive<{
        annotation: TAnnotation;
        value: In;
    }>