yesod-paginator v1.1.0.2 Release Notes

    • Functor, Foldable, and Traversable instances for Pages

    And so necessarily, Page.

    These work by applying the functions to a Pages' current Page, which is to apply it to each of the Page's items. These can be used to extend the data post-pagination; purely via fmap, or with effect using traverse.

      pages <- runDB $ do
        users <- selectPaginated 10 [UserFoo ==. foo] []
    
        -- for :: Pages User -> (User -> t UserWithPosts) -> t (Pages UserWithPosts)
    
        for users $ \user -> do
          posts <- selectList [PostUserId ==. user] [Desc PostCreatedAt, LimitTo 5]
          pure $ UserWithPosts user posts
    

    Yes, this does encourage N+1 queries, but the idea is they will not be harmful when N is small due to pagination.