Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# - Convert Int option to Int64 option

Tags:

f#

Is there better way how to do this? :

let intOption = Some(123) 
let longOption = match intOption with
                   | Some x -> Some(int64 x )
                   | None   -> None

I need to convert option of int to option of int64.

like image 582
Alamakanambra Avatar asked Oct 22 '25 14:10

Alamakanambra


2 Answers

Option.map does exactly what you need.

intOption |> Option.map int64
like image 96
TheQuickBrownFox Avatar answered Oct 24 '25 21:10

TheQuickBrownFox


The function you're looking for is Option.map:

let longOption = Option.map int64 intOption
like image 21
Vandroiy Avatar answered Oct 24 '25 22:10

Vandroiy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!