【发布时间】:2023-02-26 04:39:29
【问题描述】:
我想编写一个咖喱函数
f :: i -> a -> b
使用索引遍历
l :: IndexedTraversal' i s a
将其应用于 s 并取回 [b]。
我想出了
s ^.. l . withIndex . to (uncurry f)
但我想要一个允许我这样做的组合器itoListByOf
s & itoListByOf l f
喜欢
itoListByOf :: IndexedGetting i (Endo [b]) s a -> (i-> a -> b) -> s -> [b]
itoListByOf l f = ifoldrOf l (\i a -> (f i a :)) []
但我想确保我不会错过这个隐藏在库中的组合器,它具有更通用的类型。
【问题讨论】:
标签: haskell haskell-lens