> For the complete documentation index, see [llms.txt](https://soufatn.gitbook.io/rxjs-book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://soufatn.gitbook.io/rxjs-book/summary/observable/observable_instance_methods/sum.md).

# sum

Computes the sum of a sequence of values that are obtained by invoking an optional transform function on each element of the input sequence, else if not specified computes the sum on each item in the sequence.

## Arguments

1. `[keySelector]` *(`Scheduler`)*:  A transform function to apply to each element.  The callback is called with the following information:
   1. the value of the element
   2. the index of the element
   3. the Observable object being subscribed

## Returns

*(`Observable`)*: An observable sequence containing a single element with the sum of the values in the source sequence.

## Example

### Without a selector

### With a selector
