我正在尝试使用镜头编写具有以下类型签名的函数,但是茫然地盯着filtered
显然不起作用!
modifyElem
:: (a -> Bool) -- predicate function
-> (a -> a) -- modification to apply
-> [a]
-> [a]
如果可能的话,也可以将其概括为以下内容:
modifyElem
:: (Foldable t) -- or (Traversable t)
-> (a -> Bool)
-> (a -> a)
-> t a
-> t a
答案 0 :(得分:2)
尝试一下:
modifyElem :: Traversable t => (a -> Bool) -> (a -> a) -> t a -> t a
modifyElem predicate transform target =
target & traverse . filtered predicate %~ transform