ndmitchell / extra

Extra Haskell functions
Other
93 stars 37 forks source link

NonEmpty input in Data.List.Extra.repeatedly #95

Closed Lev135 closed 2 years ago

Lev135 commented 2 years ago

As I can see from source code repeatedly applize f only to non empty lists:

repeatedly :: ([a] -> (b, [a])) -> [a] -> [b]
repeatedly f [] = []
repeatedly f as = b : repeatedly f as'
    where (b, as') = f as

However, this is not specified in the type and the documentation also says nothing about it. It seems reasonable either to change type to (NonEmpty a -> (b, [a])) -> [a] -> [b] or just note this in docs, since not in all cases there is a suitable way to define f on an empty list.

ndmitchell commented 2 years ago

I think the best thing is probably to update the documentation - it definitely is always non-empty. Changing the type has some advantages, but is also going to break all users, so probably not a good idea now. There is https://github.com/ndmitchell/extra/blob/master/src/Data/List/NonEmpty/Extra.hs, where it might be more reasonable to add with the NonEmpty type.

Lev135 commented 2 years ago

I think the best thing is probably to update the documentation - it definitely is always non-empty. Changing the type has some advantages, but is also going to break all users, so probably not a good idea now. There is https://github.com/ndmitchell/extra/blob/master/src/Data/List/NonEmpty/Extra.hs, where it might be more reasonable to add with the NonEmpty type.

I think that this function should be in Data.List.Extra because it doesn't work with NonEmpty list as one would expect if it were in Data.List.NonEmpty.Extra. To be more precise, what changes I suggest, I've opened pool request with changed files: https://github.com/ndmitchell/extra/pull/96