# list.select()

The `list.select()` function returns the list with elements selected by comparison consisting of `$operand`, `$operator`, `$value`, and `$values...`.

{% code lineNumbers="true" %}

```scss
// Sass.
@use 'sass:list';
@use 'sass:map';
@use 'sass:meta';

// Functions.
@use '../comparison/comparison.compare.function';
@use 'list.append.function' as *;
@use 'list.empty.function' as *;
@use 'list.first.function' as *;
@use 'list.index.function' as *;
@use 'list.nth.function' as *;
@use 'remove/remove.duplicate.function' as *;

// The `list.select()` function.
@function select(
  $select: index,
  $from: null,
  $operand: value,
  $operator: '==',
  $value,
  $values...
) {
  $result: ();
  $select: if(list.length($select) == 1, any $select, $select);
  $occurrence: list.nth(
    $select,
    index($select, all, any, end, first, last, only, start)
  );
  $select: list.nth($select, index($select, has, index, type, value));
  @each $value in append((), $value, comma, $values...) {
    $do: true;
    $compared-result: ();
    $index: 1;
    @while $do == true {
      $comparison-result: comparison.compare(
        map.get(
          (
            index: $index,
            type: meta.type-of(list.nth($from, $index)),
            value: list.nth($from, $index),
          ),
          $operand
        ),
        $operator,
        $value
      );

      @if $comparison-result or ($select == has and $occurrence == only) {
        $compared-result: list.append(
          $compared-result,
          map.get(
            (
              has: $comparison-result,
              index: $index,
              type: meta.type-of(list.nth($from, $index)),
              value: list.nth($from, $index),
            ),
            $select
          ),
          comma
        );
      }

      // Break the while.
      $do: if(
        $index ==
          list.length($from) or
          (
            not empty($compared-result) and list.index(first start, $occurrence)
          ),
        false,
        $do
      );
      $index: $index + 1;
    }

    $compared-result: if(empty($compared-result), null, $compared-result);

    @if $compared-result {
      @if $select == has and list.index(all only, $occurrence) {
        $compared-result: duplicate($compared-result);
        $compared-result: if(
          list.index($compared-result, null) or
            list.index($compared-result, false),
          false,
          true
        );
      }

      $compared-result: if(
        list.index(any first start end last, $occurrence),
        list.nth(
          $compared-result,
          if(
            list.index(any first start, $occurrence),
            1,
            list.length($compared-result)
          )
        ),
        if(
          list.length($compared-result) == 1,
          first($compared-result),
          $compared-result
        )
      );
    }

    $result: list.append($result, $compared-result, comma);
  }

  // has
  @if $select == has {
    $result: if(
      list.index(all, $occurrence),
      if(list.index($result, null) or list.index($result, false), false, true),
      if(
        list.index(any, $occurrence),
        if(list.index($result, true), true, false),
        if($occurrence == only, $result, false)
      )
    );
  }

  @return if(
    list.length($result) > 0,
    if(
      list.length($result) == 1 and not (type-of(nth($result, 1)) == list),
      first($result),
      $result
    ),
    null
  );
}

```

{% endcode %}

{% embed url="<https://github.com/angular-package/sass/blob/main/list/_list.select.function.scss>" %}

### Parameters

#### **`$select`**

The value of `list` or `string` type indicates what to retrieve from the given [`$from`](#usdfrom) list.

The value of `list` type consists of occurrence and selection, in order (occurrence selection). It's changed to (selection occurrence) when selection `has` is used, and there are `has only`, `has any`, `has all`. Occurrence (`all`, `any`, `end`, `first`, `last`, `only`) indicates how often compared elements occur in the given [`$from`](#usdfrom) list. Selection can take the values `has`, `index`, `type`, `value` and indicates what to retrieve from the list.

#### **`$from`**&#x20;

The list to retrieve elements from, by the given comparison.

#### `$operand`

The value of `string` type can take (index, type, value) and indicates an operand from the list used in the comparison.

|       |                     |
| ----- | ------------------- |
| index | element's index     |
| type  | type of the element |
| value | element's value     |

#### `$operator`

The operator used to compare [`$value`](#usdvalue) and/or [`$values`](#usdvalues...) with [`$operand`](#usdoperand) of the [`$from`](#usdfrom) list.

|     |                                                 |
| --- | ----------------------------------------------- |
| !   | not                                             |
| :   | type of                                         |
| (,) | list length                                     |
| (:) | map length                                      |
| === | compatbile or comparable                        |
| ==  | equal to                                        |
| \~= | text contains the given string (string.index()) |
| >   | greater than                                    |
| >=  | greater or equal than                           |
| <   | less than                                       |
| <=  | less or equal than                              |

#### `$value`

The required value to select from the given [`$from`](#usdfrom) list.

#### `$values...`

Additional values to select from the given [`$from`](#usdfrom) list.

### Return

The return value is the list with the elements selected by the given comparison.

## Examples

```scss
// Use.
@use 'angular-package/sass/list';

// Examples.


```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.angular-package.dev/sass/list/list.select.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
