{
  "id": "accumulate",
  "title": "Accumulate",
  "url": "https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/deprecated-features/gears-v1/jvm/classes/gearsbuilder/accumulate/",
  "summary": "Reduces many records in the pipe to a single record.",
  "tags": [
    "docs",
    "operate",
    "stack"
  ],
  "last_updated": "2026-04-22T11:55:45+02:00",
  "page_type": "content",
  "content_hash": "bf1adc0257ef45533e1f1811bb9cd7e9e06d36e067a113c49eaa115c7879b6fc",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "[code example]\n\nAccumulate is a many-to-one function that iterates through the records in the pipe and reduces them to a single record.\n\nYou can provide a parameter to set the initial accumulator value. Otherwise, the initial accumulator object is null."
    },
    {
      "id": "parameters",
      "title": "Parameters",
      "role": "parameters",
      "text": "Type parameters:\n\n| Name | Description |\n|------|-------------|\n| I | The template type of the returned builder |\n\nFunction parameters:\n\n| Name | Type | Description |\n|------|------|-------------|\n| accumulator | <nobr>AccumulateOperation<T,​I></nobr> | A function with logic to update the accumulator value with each record |\n| initialValue | template type I | The initial value of the accumulated object |"
    },
    {
      "id": "returns",
      "title": "Returns",
      "role": "returns",
      "text": "Returns a GearsBuilder object with a new template type."
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "Both of the following examples count the number of records in the pipeline.\n\nWithout the `initialValue` parameter:\n\n[code example]\n\nWith the `initialValue` parameter set to 0:\n\n[code example]"
    }
  ],
  "examples": [
    {
      "id": "overview-ex0",
      "language": "java",
      "code": "public <I extends java.io.Serializable> GearsBuilder<I> accumulate​(\n    gears.operations.AccumulateOperation<T,​I> accumulator)\n\npublic <I extends java.io.Serializable> GearsBuilder<I> accumulate​(\n    I initialValue, \n    gears.operations.AccumulateOperation<T,​I> accumulator)",
      "section_id": "overview"
    },
    {
      "id": "examples-ex0",
      "language": "java",
      "code": "GearsBuilder.CreateGearsBuilder(reader).accumulate((a, r)->{\n    Integer ret = null;\n    if (a == null) {\n\t    ret = 1;\n    } else {\n\t    ret = (Integer)a;\n    }\n    return ret + 1;\n});",
      "section_id": "examples"
    },
    {
      "id": "examples-ex1",
      "language": "java",
      "code": "GearsBuilder.CreateGearsBuilder(reader).accumulate(0, (a, r)->{\n   \treturn a + 1;\n});",
      "section_id": "examples"
    }
  ]
}
