Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/fsharp/language-reference/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ The option module also includes functions that correspond to the functions that

Options can be converted to lists or arrays. When an option is converted into either of these data structures, the resulting data structure has zero or one element. To convert an option to an array, use [`Option.toArray`](https://fsharp.github.io/fsharp-core-docs/reference/fsharp-core-optionmodule.html#toArray). To convert an option to a list, use [`Option.toList`](https://fsharp.github.io/fsharp-core-docs/reference/fsharp-core-optionmodule.html#toList).

### Converting Options with Default Values

In addition to converting to lists and arrays, options can be converted to other types by providing default values using the `Option.defaultValue` function. This is particularly useful when you want to ensure that the value is not `None`. For example:

```fsharp
let optionString = Some("F#")
let defaultString = optionString |> Option.defaultValue ""
// defaultString is "F#"

let optionInt = None
let defaultInt = optionInt |> Option.defaultValue 0
// defaultInt is 0
```

The `Option.defaultValue` function allows you to handle both `Some` and `None` cases seamlessly without pattern matching.

## See also

- [F# Language Reference](index.md)
Expand Down
Loading