Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How cast string to voption struct?

i have simple struct

[<Struct>]
type Phone = private Phone of string

and i need cast to Phone voption

let toVOption (phone: string) : Phone voption = phone |> ValueOption.toObj

end i see error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Type mismatch. Expecting a 'string -> Phone voption' but given a ''a voption -> 'a' The type 'string' does not match the type ''a voption'

how correct cast string to Phone voption?

>Solution :

You need to wrap the string in a Phone, and then wrap the Phone in a ValueOption:

let toVOption (phone: string) : Phone voption = phone |> Phone |> ValueSome
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading