Skip to content

Add a saturating adjust variant? #90

@potocpav

Description

@potocpav

While writing an app with lots of DateTime manipulations, I noticed that adjust is very annoying to use, because of the Maybe return type. I don't think this is a very practical design, similarly to how (+) :: Int -> Int -> Maybe Int wouldn't be. There is often not much you can do on failure, other than just skip the operation. Needless to say, that doesn't help with correctness.

I think that saturating semantics would make more sense. Something like this:

-- | Like `adjust`, but saturates on out-of-bounds results.
shift :: forall d. Duration d => d -> DateTime -> DateTime
shift d dt = case adjust d dt of
    Nothing -> if fromDuration d > mempty then top else bottom
    Just d' -> d'

Does this sound like a good idea? I can make it into a PR, but wanted to get some feedback first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs more infoThis issue needs more info before any action can be done.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions