Header menu logo TDesu.FSharp

ValueOption Module

Functions and values

Function or value Description

ValueOption.ofCSharpTryPattern (status, value)

Full Usage: ValueOption.ofCSharpTryPattern (status, value)

Parameters:
    status : bool
    value : 'a

Returns: 'a voption
Modifiers: inline
Type parameters: 'a

Converts a C# TryXxx (bool * value) tuple to a . The success flag from the TryXxx method. The output value from the TryXxx method.

status : bool
value : 'a
Returns: 'a voption

ValueOption.ofPredicate predicate value

Full Usage: ValueOption.ofPredicate predicate value

Parameters:
    predicate : 'T -> bool - The predicate to test the value with.
    value : 'T - The value to conditionally wrap.

Returns: 'T voption
Modifiers: inline
Type parameters: 'T

Returns ValueSome(value) if predicate returns true for it, otherwise ValueNone.

predicate is a function argument: per the null policy a null or throwing predicate is a programmer error, so it is called unguarded and any exception (including on a null delegate) propagates unchanged rather than being swallowed.

predicate : 'T -> bool

The predicate to test the value with.

value : 'T

The value to conditionally wrap.

Returns: 'T voption
Example

 ValueOption.ofPredicate (fun x -> x > 0) 5   // ValueSome 5
 ValueOption.ofPredicate (fun x -> x > 0) -5  // ValueNone
Multiple items
module ValueOption from Microsoft.FSharp.Core

--------------------
[<Struct>] type ValueOption<'T> = | ValueNone | ValueSome of 'T static member Some: value: 'T -> 'T voption static member op_Implicit: value: 'T -> 'T voption member IsNone: bool with get member IsSome: bool with get member Value: 'T with get static member None: 'T voption with get

ValueOption.tryCast value

Full Usage: ValueOption.tryCast value

Parameters:
    value : obj - The boxed value to type-test.

Returns: 'T voption
Modifiers: inline
Type parameters: 'T

Type-guard cast: returns ValueSome(value :?> 'T) if value is of type 'T, otherwise ValueNone. A null input returns ValueNone rather than throwing, since a CLR type test against null never succeeds for any 'T.

value : obj

The boxed value to type-test.

Returns: 'T voption
Example

 let boxed: obj = box "hello"
 ValueOption.tryCast<string> boxed // ValueSome "hello"
 ValueOption.tryCast<int> boxed    // ValueNone
 ValueOption.tryCast<string> null  // ValueNone
val boxed: obj
type obj = System.Object
val box: value: 'T -> objnull
Multiple items
module ValueOption from Microsoft.FSharp.Core

--------------------
[<Struct>] type ValueOption<'T> = | ValueNone | ValueSome of 'T static member Some: value: 'T -> 'T voption static member op_Implicit: value: 'T -> 'T voption member IsNone: bool with get member IsSome: bool with get member Value: 'T with get static member None: 'T voption with get
Multiple items
val string: value: 'T -> string

--------------------
type string = System.String
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> = int

Type something to start searching.