我有一个function,在投放之前会向Entity
的Json添加一些数据。
现在我想将相同的函数应用到我执行的实体列表中:
getEventsR :: Handler Value
getEventsR = do
events <- runDB $ selectList [] [] :: Handler [Entity Event]
return $ object ["data" .= events]
如何将具有此类签名的函数应用于events
:
addMetaData :: EventId
-> Event
-> HandlerT App IO (Maybe Value)
addMetaData eid event = do
答案 0 :(得分:2)
利用(1,2,
实例。
Traversable
无论
getEventsR :: Handler Value
getEventsR = do
events <- runDB $ selectList [] [] :: Handler [Entity Event]
maybeValues <- sequenceA [addMetaData eid event | Entity eid event <- events]
return ...
sequenceA :: (Traversable t, Applicative app) => t (app a) -> app (t a)
应该在这里使用。 (在此示例中为sequence :: (Traversable t, Monad m) => t (m a) -> m (t a)
和t ~ []
。)