Header menu logo TDesu.FSharp

Option Module

Functions and values

Function or value Description

Option.isTrue v

Full Usage: Option.isTrue v

Parameters:
    v : bool option

Returns: bool
Modifiers: inline

Returns true if the option contains true; false otherwise. The boolean option to check.

v : bool option
Returns: bool

Option.iterIgnore f _arg1

Full Usage: Option.iterIgnore f _arg1

Parameters:
    f : 'T -> 'TResult
    _arg1 : 'T option

Modifiers: inline
Type parameters: 'T, 'TResult

Applies an action to the Some value (discarding its return value), or does nothing for None. The function to apply to the contained value.

f : 'T -> 'TResult
_arg1 : 'T option

Option.map2 f o1 o2

Full Usage: Option.map2 f o1 o2

Parameters:
    f : 'T1 -> 'T2 -> 'TResult
    o1 : 'T1 option
    o2 : 'T2 option

Returns: 'TResult option
Modifiers: inline
Type parameters: 'T1, 'T2, 'TResult

Maps a function over two option values. None if either is None. The mapping function. The first option. The second option.

f : 'T1 -> 'T2 -> 'TResult
o1 : 'T1 option
o2 : 'T2 option
Returns: 'TResult option

Option.map3 f o1 o2 o3

Full Usage: Option.map3 f o1 o2 o3

Parameters:
    f : 'T1 -> 'T2 -> 'T3 -> 'TResult
    o1 : 'T1 option
    o2 : 'T2 option
    o3 : 'T3 option

Returns: 'TResult option
Modifiers: inline
Type parameters: 'T1, 'T2, 'T3, 'TResult

Maps a function over three option values. None if any is None. The mapping function. The first option. The second option. The third option.

f : 'T1 -> 'T2 -> 'T3 -> 'TResult
o1 : 'T1 option
o2 : 'T2 option
o3 : 'T3 option
Returns: 'TResult option

Option.ofBool v

Full Usage: Option.ofBool v

Parameters:
    v : bool

Returns: unit option
Modifiers: inline

Returns Some(()) if true, None if false. The boolean value to convert.

v : bool
Returns: unit option

Option.ofCSharpTryPattern (status, value)

Full Usage: Option.ofCSharpTryPattern (status, value)

Parameters:
    status : bool
    value : 'a

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

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

status : bool
value : 'a
Returns: 'a option

Option.ofPredicate predicate value

Full Usage: Option.ofPredicate predicate value

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

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

Returns Some(value) if predicate returns true for it, otherwise None.

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 option
Example

 Option.ofPredicate (fun x -> x > 0) 5   // Some 5
 Option.ofPredicate (fun x -> x > 0) -5  // None
module Option from Microsoft.FSharp.Core

Option.ofString s

Full Usage: Option.ofString s

Parameters:
    s : string - The string to convert.

Returns: string option
Modifiers: inline

Returns None if the string is null/empty/whitespace, otherwise Some(s).

s : string

The string to convert.

Returns: string option

Option.someUnit

Full Usage: Option.someUnit

Returns: unit option

Cached Some(()) to avoid allocations.

Returns: unit option

Option.tee f opt

Full Usage: Option.tee f opt

Parameters:
    f : 'T -> unit - The side-effect function to apply.
    opt : 'T option - The option to inspect.

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

Applies a side-effect on Some and returns the option unchanged.

f : 'T -> unit

The side-effect function to apply.

opt : 'T option

The option to inspect.

Returns: 'T option

Option.toResult error _arg1

Full Usage: Option.toResult error _arg1

Parameters:
    error : 'a - The error value to use when the option is None.
    _arg1 : 'b option

Returns: Result<'b, 'a>
Modifiers: inline
Type parameters: 'a, 'b

Converts Some to Ok, None to Error with the given error value.

error : 'a

The error value to use when the option is None.

_arg1 : 'b option
Returns: Result<'b, 'a>

Option.tryCast value

Full Usage: Option.tryCast value

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

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

Type-guard cast: returns Some(value :?> 'T) if value is of type 'T, otherwise None. A null input returns None 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 option
Example

 let boxed: obj = box "hello"
 Option.tryCast<string> boxed // Some "hello"
 Option.tryCast<int> boxed    // None
 Option.tryCast<string> null  // None
val boxed: obj
type obj = System.Object
val box: value: 'T -> objnull
module Option from Microsoft.FSharp.Core
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

Option.zip o1 o2

Full Usage: Option.zip o1 o2

Parameters:
    o1 : 'T1 option - The first option.
    o2 : 'T2 option - The second option.

Returns: ('T1 * 'T2) option
Modifiers: inline
Type parameters: 'T1, 'T2

Combines two options into a tuple option. None if either is None.

o1 : 'T1 option

The first option.

o2 : 'T2 option

The second option.

Returns: ('T1 * 'T2) option

Type something to start searching.