Header menu logo TDesu.FSharp

Enum Module

Parsing and bitwise flag helpers for enums, generic over any enum type via .

Functions and values

Function or value Description

Enum.addFlag flag value

Full Usage: Enum.addFlag flag value

Parameters:
Returns: EnumShape<EnumShape<^a>>
Modifiers: inline
Type parameters: ^a

Returns value with every bit of flag set.

flag : EnumShape<EnumShape<^a>>

The flag(s) to add.

value : EnumShape<^a>

The value to add the flag(s) to.

Returns: EnumShape<EnumShape<^a>>
Example

 Enum.addFlag Permissions.Write Permissions.Read   // Read ||| Write

Enum.addFlagWhen condition flag value

Full Usage: Enum.addFlagWhen condition flag value

Parameters:
    condition : bool - Whether to add the flag.
    flag : EnumShape<EnumShape<^a>> - The flag(s) to add.
    value : EnumShape<^a> - The value to conditionally add the flag(s) to.

Returns: EnumShape<EnumShape<^a>>
Modifiers: inline
Type parameters: ^a

Adds flag to value only when condition is true; otherwise returns value unchanged.

condition : bool

Whether to add the flag.

flag : EnumShape<EnumShape<^a>>

The flag(s) to add.

value : EnumShape<^a>

The value to conditionally add the flag(s) to.

Returns: EnumShape<EnumShape<^a>>
Example

 Enum.addFlagWhen isAdmin Permissions.Write Permissions.Read

Enum.hasFlag flag value

Full Usage: Enum.hasFlag flag value

Parameters:
Returns: bool
Modifiers: inline
Type parameters: ^a

Returns true if value has every bit of flag set.

flag : EnumShape<^a>

The flag(s) to test for.

value : EnumShape<EnumShape<^a>>

The value to test.

Returns: bool
Example

 [<Flags>]
 type Permissions = None = 0 | Read = 1 | Write = 2 | Execute = 4

 Enum.hasFlag Permissions.Read (Permissions.Read ||| Permissions.Write)      // true
 Enum.hasFlag Permissions.Execute (Permissions.Read ||| Permissions.Write)   // false
[<Struct>] type Permissions = | None = 0 | Read = 1 | Write = 2 | Execute = 4
union case Option.None: Option<'T>
Permissions.Read: Permissions = 1
Permissions.Write: Permissions = 2
Permissions.Execute: Permissions = 4

Enum.removeFlag flag value

Full Usage: Enum.removeFlag flag value

Parameters:
Returns: EnumShape<EnumShape<^a>>
Modifiers: inline
Type parameters: ^a

Returns value with every bit of flag cleared.

flag : EnumShape<EnumShape<^a>>

The flag(s) to remove.

value : EnumShape<^a>

The value to remove the flag(s) from.

Returns: EnumShape<EnumShape<^a>>
Example

 Enum.removeFlag Permissions.Write (Permissions.Read ||| Permissions.Write)   // Read

Enum.removeFlagWhen condition flag value

Full Usage: Enum.removeFlagWhen condition flag value

Parameters:
    condition : bool - Whether to remove the flag.
    flag : EnumShape<EnumShape<^a>> - The flag(s) to remove.
    value : EnumShape<^a> - The value to conditionally remove the flag(s) from.

Returns: EnumShape<EnumShape<^a>>
Modifiers: inline
Type parameters: ^a

Removes flag from value only when condition is true; otherwise returns value unchanged.

condition : bool

Whether to remove the flag.

flag : EnumShape<EnumShape<^a>>

The flag(s) to remove.

value : EnumShape<^a>

The value to conditionally remove the flag(s) from.

Returns: EnumShape<EnumShape<^a>>
Example

 Enum.removeFlagWhen isBanned Permissions.Write (Permissions.Read ||| Permissions.Write)

Enum.tryParse str

Full Usage: Enum.tryParse str

Parameters:
    str : string

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

Parses a string as a case of the enum 'T, returning Some(value) or None. Matching is case-sensitive; the numeric spelling of a case is accepted, as it is by the BCL. The string to parse.

str : string
Returns: 'T option

Enum.tryParseIgnoreCase str

Full Usage: Enum.tryParseIgnoreCase str

Parameters:
    str : string

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

Parses a string as a case of the enum 'T, ignoring case, returning Some(value) or None. The string to parse.

str : string
Returns: 'T option

Enum.tryParseV str

Full Usage: Enum.tryParseV str

Parameters:
    str : string

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

Parses a string as a case of the enum 'T, returning ValueSome(value) or ValueNone. The string to parse.

str : string
Returns: 'T voption

Enum.tryParseVIgnoreCase str

Full Usage: Enum.tryParseVIgnoreCase str

Parameters:
    str : string

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

Parses a string as a case of the enum 'T, ignoring case, returning ValueSome(value) or ValueNone. The string to parse.

str : string
Returns: 'T voption

Type something to start searching.