Logo Xantham

Extensions Module

Types and nested modules

Type/Module Description

KeyOf

TypeKeyOf

PropTypeBuilder

PropertyRecord<'T, 'K>

A record implementation that allows you to access properties using a property key

keyof<'T>

Get a property key from a mapping function for the given type.

proptypekey<'T, 'ReturnType>

proptypelock<'T>

Used to represent a type can be any of the types of properties for the given generic. Create a proptypekey with lambdas accessing each of the properties to create a key which statically resolves the actual types of the underlying value.

typekeyof<'T, 'ReturnType>

Equivalent to keyof but keeps the return type.

Functions and values

Function or value Description

keyof fn

Full Usage: keyof fn

Parameters:
    fn : 'T -> obj

Returns: keyof<'T>
Modifiers: inline
Type parameters: 'T

Get a property key from a mapping function for the given type.

fn : 'T -> obj
Returns: keyof<'T>
Example

 type Book<'T> = { Title: keyof<'T> }
 type LibraryHires = {
     Witcher: int
     Dune: int
 }
 let makeBook (key: keyof<LibraryHires>): Book<LibraryHires> = {
     Title = key
 }
 let dune = makeBook (keyof<_> _.Dune)
 dune.Title.Value // "Dune"
type Book<'T> = { Title: obj }
'T
type LibraryHires = { Witcher: int Dune: int }
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

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

--------------------
type int<'Measure> = int
val makeBook: key: 'a -> Book<LibraryHires>
val key: 'a
val dune: Book<LibraryHires>
Book.Title: obj

typekeyof fn

Full Usage: typekeyof fn

Parameters:
    fn : 'T -> 'ReturnType

Returns: typekeyof<'T, 'ReturnType>
Modifiers: inline
Type parameters: 'T, 'ReturnType

Equivalent to keyof but keeps the return type.

fn : 'T -> 'ReturnType
Returns: typekeyof<'T, 'ReturnType>

Active patterns

Active pattern Description

(|KeyIs|_|) value comp

Full Usage: (|KeyIs|_|) value comp

Parameters:
    value : string
    comp : keyof<'T>

Returns: bool
Modifiers: inline
Type parameters: 'T

Pattern matching against a property key using strings.

value : string
comp : keyof<'T>
Returns: bool
Example

 type TestObject = {
     Field1: int
     Field2: string
 }
 let fieldAccessor = keyof _.Field1
 match fieldAccessor with
 | KeyIs "Field1" -> true
 | KeyIs "Field2" -> false
type TestObject = { Field1: int Field2: string }
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

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

--------------------
type int<'Measure> = int
Multiple items
val string: value: 'T -> string

--------------------
type string = System.String
val fieldAccessor: obj

(|TypeKeyIs|_|) value comp

Full Usage: (|TypeKeyIs|_|) value comp

Parameters:
Returns: bool
Modifiers: inline
Type parameters: 'T, 'U

Pattern matching against a type property key using strings.

value : string
comp : typekeyof<'T, 'U>
Returns: bool

Type something to start searching.