# exists · Rell standard library · Chromia Docs (concept)

> function exists<T>(arg: T?): boolean Checks if a value is present, i.e. not null and not empty. The negation of empty() . Accepts arguments of nullable typ

Source: https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/root/exists/

FUNCTION

# exists

```signature
function exists<T>(arg: T?): boolean
```

Checks if a value is present, i.e. not `null` and not empty.

The negation of `empty()`.

Accepts arguments of nullable type (`T?`), checking that they are not null, and of collection type
(`collection<T>`), checking that they contain at least one element. Where an argument is a nullable
collection (`collection<T>?`), it is checked both for non-nullity and non-emptiness.

Examples:

* `val x: integer? = null; exists(x)` returns `false`
* `val y: integer? = 1; exists(y)` returns `true`
* `val l1: list<integer>? = null; exists(l1)` returns `false`
* `val l2: list<integer>? = []; exists(l2)` returns `false`
* `val l3: list<integer>? = [1]; exists(l3)` returns `true`

Note that when `exists()` is used within a database at-expression, and its argument is also a database
at-expression, the inner at-expression can refer to entities of the outer one, as long as the inner uses
`@*` (as opposed to `@`, `@+` or `@?`). Such expressions are efficient as they can be translated into a
single nested SQL query.

Inner at-expressions can use `@`, `@+` or `@?`, but in those cases, the inner expression cannot refer to
entities of the outer one, and such cases are typically slow as they cannot be translated into a single
nested query. They must instead be translated into multiple SQL queries, with the existence check
occurring in the Rell runtime rather than in the database, where it could be done more efficiently.
The translation into multiple queries also prevents the inner expression from referencing the outer
expression, as this is only possible through a translation into SQL that leverages the scoping rules of
nested SQL queries.

Examples:

* `user @* { exists( company @* { .city == user.city } ) }` returns all `user`s who share a `city` with
  a `company`.
* `user @* { exists( company @* { user.city } ) }` is equivalent to the above, but uses the more concise
  attribute matching syntax.

**Returns**

`true` if `value` is not `null` and not an empty collection, `false` otherwise

**See Also**

1. [`empty` - Rell Standard Library](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/root/empty/)

Since 0.6.0

[View this page on docs.chromia.com](https://docs.chromia.com/pages/rell-stdlib/-rell%20-system%20-library/%5Broot%5D/exists.html)Generated API reference, mirrored from the live docs
