Table of Contents

Method IfPresent

Namespace
DSharpPlus.Entities
Assembly
DSharpPlus.dll

IfPresent<TTarget>(Func<T, TTarget>)

Performs a mapping operation on the current Optional<T>, turning it into an Optional holding a TTarget instance if the source optional contains a value; otherwise, returns an Optional<T> of that same type with no value.

public Optional<TTarget> IfPresent<TTarget>(Func<T, TTarget> mapper)

Parameters

mapper Func<T, TTarget>

The mapping function to apply on the current value if it exists

Returns

Optional<TTarget>

An Optional<T> containing a value denoted by calling mapper if the current Optional<T> contains a value; otherwise, an empty Optional<T> of the target type.

Type Parameters

TTarget

The type of the target value returned by mapper