简化高阶函数中的匿名函数

自己

假设我有以下几种类型:

data Test = Test1 | Test2
            deriving (Eq, Show)

data TestDS = TestDS {
      testField1 :: String,
      testField2 :: Test
    } deriving (Eq, Show)

testFilter :: [TestDS] -> [TestDS]
testFilter tdata = filter (\x -> testField2 x == Test2) tdata

是否可以将上述过滤器功能转换为以下形式:

filter (Test2 == testField2) tdata

(上面的过滤器功能当然会产生编译错误)

Jamshidh

这是你想要的吗?

filter ((Test2 ==) . testField2) tdata

请记住,(Test2 ==)和testField2都是可以组合的函数。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章