这个Bool-producer对Maybe-producer函数是否出现在任何公共库中? [英] Does this Bool-producer to Maybe-producer function appear in any common library?

查看:129
本文介绍了这个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函数是否出现在任何公共库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆