Alamakanambra
Alamakanambra

Reputation: 7861

F# - Convert Int option to Int64 option

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.

Upvotes: 4

Views: 871

Answers (2)

TheQuickBrownFox
TheQuickBrownFox

Reputation: 10624

Option.map does exactly what you need.

intOption |> Option.map int64

Upvotes: 3

Vandroiy
Vandroiy

Reputation: 6223

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

let longOption = Option.map int64 intOption

Upvotes: 3

Related Questions