本文介绍了这个Bool-producer对Maybe-producer函数是否出现在任何公共库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现自己想要这个小小的函数,但它似乎不在 Data.Maybe 中。

  splat ::(a  - > Bool) - > a  - >也许是
splat c a
| c a =只是
|否则= Nothing


解决方案 ://hackage.haskell.org/package/monadplusrel =nofollow> monadplus 完全包含这个函数,名为:

  partial ::(a  - > Bool) - > a  - >可能是


I found myself wanting this tiny little function, but it doesn't seem to be in Data.Maybe. Is it somewhere else?

splat :: (a -> Bool) -> a -> Maybe a
splat c a
  | c a       = Just a
  | otherwise = Nothing
解决方案

The package monadplus contains exactly this function, named partial:

partial :: (a -> Bool) -> a -> Maybe a

这篇关于这个Bool-producer对Maybe-producer函数是否出现在任何公共库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 10:12