> ## Documentation Index
> Fetch the complete documentation index at: https://docs.graphext.com/llms.txt
> Use this file to discover all available pages before exploring further.

# slice

> Extract a range/slice of elements from a column of texts or lists. 

Using `start`, `stop` and `step` to define a range of indices, the corresponding range of elements is extracted
from each text or list in the input column.

Note: indices start at 0, and a `stop` of 3 means elements up to but *not* including the element at index 3
will be extracted. In particular this means simply specifying `"stop": 3` (setting or leaving `start` at its
default of 0), will extract 3 elements in total.

## Usage

The following examples show how the step can be used in a recipe.

<Accordion title="Examples" icon="code" defaultOpen="true">
  <Tabs>
    <Tab title="Example 1">
      Extract the first 100 characters from a text column

      ```stan theme={null}
      slice(ds.description, {"start": 0, "stop": 100, "out_type": "text"}) -> (ds.description_short)
      ```
    </Tab>

    <Tab title="Example 2">
      Extract the second element from a list column

      ```stan theme={null}
      slice(ds.coordinates, {"start": 1, "stop": 2, "out_type": "number"}) -> (ds.latitude)
      ```
    </Tab>

    <Tab title="Signature">
      General syntax for using the step in a recipe. Shows the inputs and outputs the step is expected to receive and will produce respectively. For futher details see sections below.

      ```stan theme={null}
      slice(input: text|list, {
          "param": value,
          ...
      }) -> (output: column)
      ```
    </Tab>
  </Tabs>
</Accordion>

## Inputs & Outputs

The following are the inputs expected by the step and the outputs it produces. These are generally
columns (`ds.first_name`), datasets (`ds` or `ds[["first_name", "last_name"]]`) or models (referenced
by name e.g. `"churn-clf"`).

<Accordion title="Inputs" icon="right-to-bracket">
  <ParamField path="input" type="column[text|list]" required>
    A column containing texts or lists to extract a range of characters or elements from.
  </ParamField>
</Accordion>

<Accordion title="Outputs" icon="right-from-bracket">
  <ParamField path="output" type="column" required>
    Contains the extracted slices. The type depends on the `out_type` parameter, and needs to be consistent with the transformation.
  </ParamField>
</Accordion>

## Configuration

The following parameters can be used to configure the behaviour of the step by including them in
a json object as the last "input" to the step, i.e. `step(..., {"param": "value", ...}) -> (output)`.

<Accordion title="Parameters" defaultOpen="true" icon="sliders">
  <ParamField path="start" type="[integer, null]">
    Index of the *first* element to be extracted from each string or list in the input column.
  </ParamField>

  <ParamField path="stop" type="[integer, null]">
    Index at which to stop including elements from the list.
    The element *at* the `stop` index will *not* be included. As an example, `"start": 0, "stop": 3`
    will include all elements up to but not including the element at index 3, thus extracting a
    total of 3 elements.
  </ParamField>

  <ParamField path="step" type="[integer, null]" default="1">
    Step size used to move from `start` to `stop` index.
    E.g., if `"step": 2`, only every second element from the range \[`start`, `stop`] is returned.
  </ParamField>

  <ParamField path="out_type" type="string">
    Select types using their name.

    Values must be one of the following:

    `category` `date` `number` `boolean` `url` `sex` `text` `currency` `list[number]` `list[category]` `list[url]` `list[boolean]` `list[date]` `list[currency]`
  </ParamField>
</Accordion>
