---
title: Std.Maybe
---

Optional values: a type-safe alternative to null.

## Types

### Maybe

```saga
type Maybe a =
  | Nothing
  | Just a
```

A value that is either present (Just) or absent (Nothing).

## Functions

### is_just

```saga
fun is_just : Maybe a -> Bool
```

Returns True if the value is Just.

### is_nothing

```saga
fun is_nothing : Maybe a -> Bool
```

Returns True if the value is Nothing.

### map

```saga
fun map : (f: a -> b) -> (m: Maybe a) -> Maybe b
```

Applies a function to the inner value if Just, otherwise returns Nothing.

### unwrap_or

```saga
fun unwrap_or : (default: a) -> (m: Maybe a) -> a
```

Returns the inner value or a default if Nothing.

### unwrap

```saga
fun unwrap : (m: Maybe a) -> a where {a: Debug}
```

Returns the inner value. Panics on Nothing.

### and_then

```saga
fun and_then : (f: a -> Maybe b) -> (m: Maybe a) -> Maybe b
```

Chains a function that returns Maybe. Returns Nothing if the input is Nothing.

### or_else

```saga
fun or_else : (fallback: Maybe a) -> (m: Maybe a) -> Maybe a
```

Returns the first Just value, or Nothing if both are Nothing.

