F# 跳过序列中的空值<;可为空<;int>&燃气轮机;在FSharp.图表中
我有F# 跳过序列中的空值<;可为空<;int>&燃气轮机;在FSharp.图表中,f#,fsharpchart,F#,Fsharpchart,我有seq,需要创建漂亮的绘图,但没有空值。 这是我的密码: open System #r """..\packages\FSharp.Charting.0.90.14\lib\net40\FSharp.Charting.dll""" #load """..\packages\FSharp.Charting.0.90.14\FSharp.Charting.fsx""" open FSharp.Charting //in a real world replaced by .csv with em
seq
,需要创建漂亮的绘图,但没有空值。
这是我的密码:
open System
#r """..\packages\FSharp.Charting.0.90.14\lib\net40\FSharp.Charting.dll"""
#load """..\packages\FSharp.Charting.0.90.14\FSharp.Charting.fsx"""
open FSharp.Charting
//in a real world replaced by .csv with empty values
let seqWithNullInt = seq[Nullable 10 ; Nullable 20 ; Nullable (); Nullable 40; Nullable 50]
//let seqWithNullInt = seq[ 10 ; 20 ; 30; 40; 50] //works fine
let bothSeq = seqWithNullInt |> Seq.zip {1..5}
Chart.Line bothSeq // Error because of nullable int
以下是我的愿景:
如何跳过空值?我不想用最近的或什么东西来代替它们,我需要从图表中跳过它们。。有什么解决办法吗 类似的东西可能会起作用(请注意,我使用了
选项
值而不是空值,因为这在F#中更为惯用):
这将输出[(1,10)、(2,20);(4,40)、(5,50)]
。我不知道FSharp.Charting API,所以我无法告诉您哪个函数将获取X,Y对列表并绘制所需的图形,但从那里到图形应该相对简单
let neitherPairHasNoneInValue (pair1, pair2) =
pair1 |> snd |> Option.isSome && pair2 |> snd |> Option.isSome
let seqWithNone = Seq.ofList [Some 10; Some 20; None; Some 40; Some 50]
let pairsWithoutNone = seqWithNone
|> Seq.zip {1..5}
|> Seq.pairwise
|> Seq.filter neitherPairHasNoneInValue
printfn "%A" pairsWithoutNone