FSharpx.Extras


Option Module

Types

Type Description

MaybeBuilder

The maybe monad. This monad is my own and uses an 'T option. Others generally make their own Maybe<'T> type from Option<'T>. The builder approach is from Matthew Podwysocki's excellent Creating Extended Builders series http://codebetter.com/blogs/matthew.podwysocki/archive/2010/01/18/much-ado-about-monads-creating-extended-builders.aspx.

Functions and values

Function or value Description

x *> y

Full Usage: x *> y

Parameters:
    x : 'a option
    y : 'b option

Returns: 'b option
Modifiers: inline

Sequence actions, discarding the value of the first argument.

x : 'a option
y : 'b option
Returns: 'b option

x <* y

Full Usage: x <* y

Parameters:
    x : 'a option
    y : 'b option

Returns: 'a option
Modifiers: inline

Sequence actions, discarding the value of the second argument.

x : 'a option
y : 'b option
Returns: 'a option

f <!> m

Full Usage: f <!> m

Parameters:
    f : 'a -> 'b
    m : 'a option

Returns: 'b option
Modifiers: inline

Infix map

f : 'a -> 'b
m : 'a option
Returns: 'b option

f <*> m

Full Usage: f <*> m

Parameters:
    f : ('a -> 'b) option
    m : 'a option

Returns: 'b option
Modifiers: inline

Sequential application

f : ('a -> 'b) option
m : 'a option
Returns: 'b option

<=<x

Full Usage: <=<x

Parameters:
    x : 'a -> 'b option

Returns: ('c -> 'a option) -> 'c -> 'b option
Modifiers: inline

Right-to-left Kleisli composition

x : 'a -> 'b option
Returns: ('c -> 'a option) -> 'c -> 'b option

f =<< m

Full Usage: f =<< m

Parameters:
    f : 'a -> 'b option
    m : 'a option

Returns: 'b option
Modifiers: inline

Flipped >>=

f : 'a -> 'b option
m : 'a option
Returns: 'b option

(>=>) f g x

Full Usage: (>=>) f g x

Parameters:
    f : 'a -> 'b option
    g : 'b -> 'c option
    x : 'a

Returns: 'c option
Modifiers: inline

Left-to-right Kleisli composition

f : 'a -> 'b option
g : 'b -> 'c option
x : 'a
Returns: 'c option

m >>. f

Full Usage: m >>. f

Parameters:
    m : 'a option
    f : 'b option

Returns: 'b option
Modifiers: inline

Sequentially compose two maybe actions, discarding any value produced by the first

m : 'a option
f : 'b option
Returns: 'b option

m >>= f

Full Usage: m >>= f

Parameters:
    m : 'a option
    f : 'a -> 'b option

Returns: 'b option
Modifiers: inline

Sequentially compose two actions, passing any value produced by the first as an argument to the second.

m : 'a option
f : 'a -> 'b option
Returns: 'b option

ap m f

Full Usage: ap m f

Parameters:
    m : 'a option
    f : ('a -> 'b) option

Returns: 'b option
Modifiers: inline

Sequential application

m : 'a option
f : ('a -> 'b) option
Returns: 'b option

cast o

Full Usage: cast o

Parameters:
    o : obj

Returns: 'a option
Modifiers: inline

Attempts to cast an object. Returns None if unsuccessful.

o : obj
Returns: 'a option

concat x

Full Usage: concat x

Parameters:
    x : 'a option option

Returns: 'a option
Modifiers: inline

Concatenates an option of option.

x : 'a option option
Returns: 'a option

filter pred _arg1

Full Usage: filter pred _arg1

Parameters:
    pred : 'b -> bool
    _arg1 : 'b option

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

Applies a predicate to the option. If the predicate returns true, returns Some x, otherwise None.

pred : 'b -> bool
_arg1 : 'b option
Returns: 'b option

foldM f s

Full Usage: foldM f s

Parameters:
    f : 'a -> 'b -> 'a option
    s : 'a

Returns: 'b seq -> 'a option
f : 'a -> 'b -> 'a option
s : 'a
Returns: 'b seq -> 'a option

fromTryPattern tryFun input

Full Usage: fromTryPattern tryFun input

Parameters:
    tryFun : 'input -> bool * 'output
    input : 'input

Returns: 'output option

transforms a function in the Try...(input, out output) style into a function of type: input -> output Option Example: fromTryPattern(System.Double.TryParse) See Examples.Option

tryFun : 'input -> bool * 'output
input : 'input
Returns: 'output option

getOrDefault _arg1

Full Usage: getOrDefault _arg1

Parameters:
    _arg1 : 'a option

Returns: 'a

Gets the value associated with the option or the default value for the type.

_arg1 : 'a option
Returns: 'a

getOrElse v _arg1

Full Usage: getOrElse v _arg1

Parameters:
    v : 'a
    _arg1 : 'a option

Returns: 'a
Modifiers: inline

Gets the value associated with the option or the supplied default value.

v : 'a
_arg1 : 'a option
Returns: 'a

getOrElseF v _arg1

Full Usage: getOrElseF v _arg1

Parameters:
    v : unit -> 'a
    _arg1 : 'a option

Returns: 'a
Modifiers: inline

Gets the value associated with the option or the supplied default value from a function.

v : unit -> 'a
_arg1 : 'a option
Returns: 'a

getOrElseLazy v _arg1

Full Usage: getOrElseLazy v _arg1

Parameters:
    v : Lazy<'a>
    _arg1 : 'a option

Returns: 'a
Modifiers: inline

Gets the value associated with the option or the supplied default value.

v : Lazy<'a>
_arg1 : 'a option
Returns: 'a

getOrElseWith v f _arg1

Full Usage: getOrElseWith v f _arg1

Parameters:
    v : 'a
    f : 'b -> 'a
    _arg1 : 'b option

Returns: 'a
Modifiers: inline
v : 'a
f : 'b -> 'a
_arg1 : 'b option
Returns: 'a

getOrFail m _arg1

Full Usage: getOrFail m _arg1

Parameters:
    m : string
    _arg1 : 'a option

Returns: 'a
Modifiers: inline

Gets the value associated with the option or fails with the supplied message.

m : string
_arg1 : 'a option
Returns: 'a

getOrRaise e _arg1

Full Usage: getOrRaise e _arg1

Parameters:
Returns: 'a
Modifiers: inline

Gets the value associated with the option or raises the supplied exception.

e : Exception
_arg1 : 'a option
Returns: 'a

getOrReraise e _arg1

Full Usage: getOrReraise e _arg1

Parameters:
    e : exn
    _arg1 : 'a option

Returns: 'a
Modifiers: inline

Gets the value associated with the option or reraises the supplied exception.

e : exn
_arg1 : 'a option
Returns: 'a

isNone o

Full Usage: isNone o

Parameters:
Returns: bool
Modifiers: inline
Type parameters: 'a
o : Option<'a>
Returns: bool

isSome o

Full Usage: isSome o

Parameters:
Returns: bool
Modifiers: inline
Type parameters: 'a
o : Option<'a>
Returns: bool

lift2 f a b

Full Usage: lift2 f a b

Parameters:
    f : 'd -> 'e -> 'f
    a : 'd option
    b : 'e option

Returns: 'f option
Modifiers: inline
Type parameters: 'd, 'e, 'f

Promote a function to a monad/applicative, scanning the monadic/applicative arguments from left to right.

f : 'd -> 'e -> 'f
a : 'd option
b : 'e option
Returns: 'f option

mapM f x

Full Usage: mapM f x

Parameters:
    f : 'a -> 'b option
    x : 'a list

Returns: 'b list option
Modifiers: inline
f : 'a -> 'b option
x : 'a list
Returns: 'b list option

maybe

Full Usage: maybe

Returns: MaybeBuilder
Returns: MaybeBuilder

monoid m

Full Usage: monoid m

Parameters:
Returns: Monoid<'a option>

Option wrapper monoid

m : ISemigroup<'a>
Returns: Monoid<'a option>

ofBool b

Full Usage: ofBool b

Parameters:
    b : bool

Returns: unit option
Modifiers: inline

True -> Some(), False -> None

b : bool
Returns: unit option

ofBoolAndValue (arg1, arg2)

Full Usage: ofBoolAndValue (arg1, arg2)

Parameters:
    arg0 : bool
    arg1 : 'a

Returns: 'a option
Modifiers: inline

If true,value then returns Some value. Otherwise returns None. Useful to process TryXX style functions.

arg0 : bool
arg1 : 'a
Returns: 'a option

ofChoice _arg1

Full Usage: ofChoice _arg1

Parameters:
Returns: 'c option

Maps Choice 1Of2 to Some value, otherwise None.

_arg1 : Choice<'c, 'd>
Returns: 'c option

ofNullable n

Full Usage: ofNullable n

Parameters:
Returns: 'a option

Maps a Nullable to Option

n : Nullable<'a>
Returns: 'a option

ofResult _arg1

Full Usage: ofResult _arg1

Parameters:
Returns: 'c option

Maps Result Ok to Some value, otherwise None.

_arg1 : Result<'c, 'd>
Returns: 'c option

ofUnchecked x

Full Usage: ofUnchecked x

Parameters:
    x : 'a

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

Maps Unchecked object when null to None, otherwise Some value. It's useful when getting data from external sources, pe.

x : 'a
Returns: 'a option

option defaultValue map _arg1

Full Usage: option defaultValue map _arg1

Parameters:
    defaultValue : 'U
    map : 'T -> 'U
    _arg1 : 'T option

Returns: 'U

Haskell-style maybe operator

defaultValue : 'U
map : 'T -> 'U
_arg1 : 'T option
Returns: 'U

orElse v _arg1

Full Usage: orElse v _arg1

Parameters:
    v : 'a option
    _arg1 : 'a option

Returns: 'a option
Modifiers: inline

Gets the option if Some x, otherwise the supplied default value.

v : 'a option
_arg1 : 'a option
Returns: 'a option

orElseLazy v _arg1

Full Usage: orElseLazy v _arg1

Parameters:
    v : Lazy<'a option>
    _arg1 : 'a option

Returns: 'a option
Modifiers: inline
v : Lazy<'a option>
_arg1 : 'a option
Returns: 'a option

returnM x

Full Usage: returnM x

Parameters:
    x : 'a

Returns: 'a option
Modifiers: inline

Inject a value into the option type

x : 'a
Returns: 'a option

sequence s

Full Usage: sequence s

Parameters:
    s : 'b option list

Returns: 'b list option
Modifiers: inline
Type parameters: 'b
s : 'b option list
Returns: 'b list option

someIf condition x

Full Usage: someIf condition x

Parameters:
    condition : 'a -> bool
    x : 'a

Returns: 'a option

Checks condition on x - if true returns Some x else None

condition : 'a -> bool
x : 'a
Returns: 'a option

toNullable _arg1

Full Usage: toNullable _arg1

Parameters:
    _arg1 : 'a option

Returns: Nullable<'a>

Maps an Option to Nullable

_arg1 : 'a option
Returns: Nullable<'a>

tryParseWith func

Full Usage: tryParseWith func

Parameters:
    func : 'a -> bool * 'b

Returns: 'a -> 'b option
Modifiers: inline

Converts a function returning bool,value to a function returning value option. Useful to process TryXX style functions.

func : 'a -> bool * 'b
Returns: 'a -> 'b option