Series.hasNot 中有错误吗?
Is there a bug in Series.hasNot?
Deedle
中函数 Series.hasNot
的帮助说:
Returns true when the series does not contains value for the specified key
在以下示例中,函数似乎不是这样工作的:
let election =
[ "Party A", 304
"Party B", 25
"Party C", 570
"Party Y", 2
"Party Z", 258 ]
|> series
let bhnt =
election
|> Series.hasNot "Party A"
printfn "%A" <| bhnt
// true
// val bhnt : bool = true
// val it : unit = ()
我是不是漏掉了什么?
我刚看了 Deedle source 并看到以下内容:
let has key (series:Series<'K, 'T>) = series.TryGet(key).HasValue
let hasNot key (series:Series<'K, 'T>) = series.TryGet(key).HasValue
是的,您发现了一个错误。 hasNot
函数应该看起来像 not (series.TryGet(key).HasValue)
.
解决方法: 在修复此错误之前,您可以通过将代码中出现的所有 Series.hasNot key
替换为 Series.has key
然后管道来解决此问题通过 not
函数。例如,
let bhnt =
election
|> Series.has "Party A"
|> not
或者,如果你觉得这样更好看,你也可以这样写:
let bhnt =
election
|> (not << Series.has "Party A")
这两种写法是等价的;您更喜欢使用哪一个取决于您对函数式编程的熟悉程度。有些人觉得 <<
语法读起来更自然,而另一些人则觉得它很奇怪并想坚持只使用 |>
。这完全取决于您对函数式编程的经验。选择这两者中您觉得最自然的一个。
Deedle
中函数 Series.hasNot
的帮助说:
Returns true when the series does not contains value for the specified key
在以下示例中,函数似乎不是这样工作的:
let election =
[ "Party A", 304
"Party B", 25
"Party C", 570
"Party Y", 2
"Party Z", 258 ]
|> series
let bhnt =
election
|> Series.hasNot "Party A"
printfn "%A" <| bhnt
// true
// val bhnt : bool = true
// val it : unit = ()
我是不是漏掉了什么?
我刚看了 Deedle source 并看到以下内容:
let has key (series:Series<'K, 'T>) = series.TryGet(key).HasValue
let hasNot key (series:Series<'K, 'T>) = series.TryGet(key).HasValue
是的,您发现了一个错误。 hasNot
函数应该看起来像 not (series.TryGet(key).HasValue)
.
解决方法: 在修复此错误之前,您可以通过将代码中出现的所有 Series.hasNot key
替换为 Series.has key
然后管道来解决此问题通过 not
函数。例如,
let bhnt =
election
|> Series.has "Party A"
|> not
或者,如果你觉得这样更好看,你也可以这样写:
let bhnt =
election
|> (not << Series.has "Party A")
这两种写法是等价的;您更喜欢使用哪一个取决于您对函数式编程的熟悉程度。有些人觉得 <<
语法读起来更自然,而另一些人则觉得它很奇怪并想坚持只使用 |>
。这完全取决于您对函数式编程的经验。选择这两者中您觉得最自然的一个。