Show / Hide Table of Contents
  • MaybeSharp
    • Maybe<T>
      • As
      • Bind
      • Cast
      • CompareTo
      • Equality
      • Equals
      • Explicit
      • GetHashCode
      • GreaterThan
      • GreaterThanOrEqual
      • HasValue
      • Implicit
      • Inequality
      • IsEmpty
      • LessThan
      • LessThanOrEqual
      • Maybe
      • Nothing
      • ToString
      • Value
  • MaybeSharp.Extensions
    • MaybeDictionaryExtensions
      • TryGetValue
    • MaybeExtensions
      • Coalesce
      • Or
      • Select
      • SelectMany
      • SelectNonempty
      • ToNullable
      • ValueOr
      • ValueOrException
      • WhenNothing
      • WhenSomething
      • Where
    • MaybeStringExtensions
      • TryParseBoolean
      • TryParseByte
      • TryParseChar
      • TryParseDateTime
      • TryParseDateTimeOffset
      • TryParseDecimal
      • TryParseDouble
      • TryParseInt
      • TryParseInt16
      • TryParseInt64
      • TryParseSingle
    • NullableExtensions
      • ToMaybe

Method ValueOr

ValueOr<T>(Maybe<T>, T)

Returns the value of the Maybe{T} instance if it is non-empty, otherwise returns value.

Declaration
public static T ValueOr<T>(this Maybe<T> source, T value)
Parameters
Type Name Description
Maybe<T> source

The Mabye{T} instance whose value is returned if it is not empty.

T value

The value to return if the Maybe{T} is empty.

Returns
Type Description
T

Either the value of Maybe{T} or value.

Type Parameters
Name Description
T

The sub-type of the Maybe{T} instances.

ValueOr<T>(Maybe<T>, Func<T>)

Returns the value of the Maybe{T} instance if it is non-empty, otherwise returns the result of the valueFactory function.

Declaration
public static T ValueOr<T>(this Maybe<T> source, Func<T> valueFactory)
Parameters
Type Name Description
Maybe<T> source

The Mabye{T} instance whose value is returned if it is not empty.

Func<T> valueFactory

A function the is used to calculate the return value if source is empty.

Returns
Type Description
T

Either the value of source or the result of calling valueFactory if the former is empty.

Type Parameters
Name Description
T

The sub-type of the Maybe{T} instances.

Back to top Copyright (c) 2017 Troy Willmot