Giter Site home page Giter Site logo

Add `flip foldMap` about extra HOT 5 OPEN

ndmitchell avatar ndmitchell commented on August 16, 2024
Add `flip foldMap`

from extra.

Comments (5)

ndmitchell avatar ndmitchell commented on August 16, 2024

It seems to be a pattern that these functions come in flipped and non-flipped versions, so it doesn't seem unreasonable. I think the question of what it should be named is probably key. If the name seems to obviously indicate what it does, then it seems good to add. If the name isn't obvious, then it would require people to look up, and probably makes code using it harder to understand. I don't have any good ideas for a name, but I think that's the key question.

from extra.

ysangkok avatar ysangkok commented on August 16, 2024

What about mapMconcat or mapSummarize or mapSummarise or just plain summarize? @cdsmith has referred to mconcat as summarizing: https://cdsmithus.medium.com/monoids-are-composable-list-summarizers-77d2baf23ffc

from extra.

cdsmith avatar cdsmith commented on August 16, 2024

While I did write that article, I don't think the word "summarize" is sufficiently precise to make a good name. Here are some candidates off the top of my head:

  • foldEach - this is probably my favorite name in general
  • foldFor - because sometimes for is used to mean flip map, though lately it's been more often used for flip traverse instead. A variant is foldOver, since we talk about folding over a list.
  • mapFold - I'm not a fan, but it's a sort of flip of foldMap.

from extra.

endgame avatar endgame commented on August 16, 2024

I stand by my suggestion of paMdolf, but I think that in the age of -XBlockArguments (GHC >=8.6.1) the need for a distinct function is much lower: Just 3 & foldMap \m -> Sum (m * 2) is actually pretty nice.

from extra.

ndmitchell avatar ndmitchell commented on August 16, 2024

Agreed summarise doesn't seem right, since a function called summarise could do almost anything. I'm ok with foldEach/foldFor/mapFold, but have no strong preference on which, or if the function is useful enough with block arguments etc.

from extra.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.