serokell / universum

:milky_way: Prelude written in @Serokell
MIT License
176 stars 28 forks source link

Add something similar to `fromScratch` #76

Closed chshersh closed 6 years ago

chshersh commented 6 years ago

log-warper has useful function fromScratch:

fromScratch :: Monoid m => State m a -> m
fromScratch = executingState mempty

I think we should add similar family of (executing|evaluating|using) function for Monoid because it's very often pattern when you want to run State computation starting from empty value. Consider next examples:

  1. List/DList
  2. Map/HashMap/IntMap
  3. HashSet/IntSet
  4. Tuple etc.

I propose next naming: (using|evaluating|executing)Mempty.

For now I see this only usable for State[T]. But still very convenient.

gromakovsky commented 6 years ago

I think that non-standard functions should be added to a custom prelude only if there is a really good reason to do so. I don't see a really good reason in this case. Probably this function will be used once per few thousands of LOCs. I agree that in some cases this having function is convenient, but I don't think it should be in prelude. That being said, I also sorta don't like stuff like one (but one is more useful).

chshersh commented 6 years ago

@gromakovsky Thanks! This is the exact feedback I want to receive. I find this function useful. But you're right that it won't be used very often and it's not something basic and crucial. I saw several usages of this function across several projects. But when adding new functions we should also consider amount of effort people need to spend to learn new function. And it will be harder for new people to work with projects which use universum.