Option type

optional typeMaybe typeoptional objects
In programming languages (more so functional programming languages) and type theory, an option type or maybe type is a polymorphic type that represents encapsulation of an optional value; e.g., it is used as the return type of functions which may or may not return a meaningful value when they are applied.wikipedia
44 Related Articles

Nullable type

nullNullableDiscriminated null value
A distinct, but related concept outside of functional programming, which is popular in object-oriented programming, is called nullable types (often expressed as ). Kotlin emulates option with a Nullable type which is expressed using a question mark:
In statically-typed languages, a nullable type is an option type, while in dynamically-typed languages (where values have types, but variables do not), equivalent behavior is provided by having a single null value.

Monad (functional programming)

monadsmonadmonadic
The option type is also a monad where: The monadic nature of the option type is useful for efficiently tracking failure and errors.
The first step towards this goal might be to create an option type that will mark a value as either carrying a value of some type ( can be any type) or carrying no value.

Tagged union

sum typediscriminated unionSum
This expresses the fact that for a given set of values in A, an option type adds exactly one additional value (the empty value) to the set of valid values for A. This is reflected in programming by the fact that in languages having tagged unions, option types can be expressed as the tagged union of the encapsulated type plus a unit type.
Like option types and exception handling, tagged unions are sometimes used to handle the occurrence of exceptional results.

Rust (programming language)

RustRust programming languageCargo
To replicate the function in other languages of pointers being either valid or, such as in linked list or binary tree data structures, the Rust core library provides an option type, which can be used to test if a pointer has value or.

Swift (programming language)

SwiftSwift 3Swift programming language
An important new feature in Swift is option types, which allow references or values to operate in a manner similar to the common pattern in C, where a pointer may refer to a value or may be null.

Programming language

programming languageslanguagedialect
In programming languages (more so functional programming languages) and type theory, an option type or maybe type is a polymorphic type that represents encapsulation of an optional value; e.g., it is used as the return type of functions which may or may not return a meaningful value when they are applied.

Functional programming

functionalfunctional programming languagefunctional language
In programming languages (more so functional programming languages) and type theory, an option type or maybe type is a polymorphic type that represents encapsulation of an optional value; e.g., it is used as the return type of functions which may or may not return a meaningful value when they are applied.

Type theory

theory of typestypestype
In programming languages (more so functional programming languages) and type theory, an option type or maybe type is a polymorphic type that represents encapsulation of an optional value; e.g., it is used as the return type of functions which may or may not return a meaningful value when they are applied.

Parametric polymorphism

parametrically polymorphicimpredicative polymorphismparametric
In programming languages (more so functional programming languages) and type theory, an option type or maybe type is a polymorphic type that represents encapsulation of an optional value; e.g., it is used as the return type of functions which may or may not return a meaningful value when they are applied.

Object-oriented programming

object-orientedobject orientedobject-oriented programming language
A distinct, but related concept outside of functional programming, which is popular in object-oriented programming, is called nullable types (often expressed as ).

Unit type

unit
This expresses the fact that for a given set of values in A, an option type adds exactly one additional value (the empty value) to the set of valid values for A. This is reflected in programming by the fact that in languages having tagged unions, option types can be expressed as the tagged union of the encapsulated type plus a unit type.

Curry–Howard correspondence

Curry–Howard isomorphismCurry-Howard correspondencepropositions-as-types
In the Curry–Howard correspondence, option types are related to the annihilation law for ∨: x∨1=1.

Absorption law

absorptionabsorption identitiesannihilation law
In the Curry–Howard correspondence, option types are related to the annihilation law for ∨: x∨1=1.

Collection (abstract data type)

collectioncontainercontainers
An option type can also be seen as a collection containing either one or zero elements.

Agda (programming language)

AgdaAgda variant
* In Agda, it is named Maybe with variants nothing and just a.

OCaml

MetaOCamlOCaml Package ManagerOPAM
* In OCaml, it is defined as Some of 'a.

Scala (programming language)

ScalaScala programming languageScala.js
Scala implements as a parameterized type, so a variable can be an, accessed as follows:

Kotlin (programming language)

KotlinKotlin Programming Language
Kotlin emulates option with a Nullable type which is expressed using a question mark:

Ada (programming language)

AdaAda programming languageAda 83
Ada does not implement option-types directly, however it provides a more robust method for parameterizing a record known as discriminated types.