Passing a seq from F# to RProvider

后端 未结 2 968
礼貌的吻别
礼貌的吻别 2020-12-22 02:22

I asked this question last week regarding seq values passed to RProvider. I had hoped that I\'d be able to apply the accepted answer there

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-22 03:09

    You can use Option.toObj.

    For example:

    let l1 = [ Some "x"; None; Some "y"] 
    
    let l2 = l1 |> List.map (Option.toObj)
    // val l2 : string list = ["x"; null; "y"]
    

    And you can use Option.toNullable for number values, but it would convert to type Nullable, and None would also be null. For some reason this doesn't work the other way round:

    let l3 = l2 |> List.map (Option.ofObj)
    // val l3 : string option list = [Some "x"; null; Some "y"]
    

    I don't know if that's intended or a bug.

    Edit : Option.ofObj does work properly. F# Interactive displays None as null when it is in a list for some reason.

提交回复
热议问题