Hello!
I’m learning and starting to notice a pattern I can’t quite put my finger on, it’s bugging me
Let’s say Just
represents the success of an operation, Nothing
represents a failure.
So if I’ve got Nothing, I won’t go to step 1.
But if I passed step 0, then I can go to step 1.
I may or may not use x
:
Prelude> Nothing >>= \x -> Just 1
Nothing
Prelude> Just 0 >>= \x -> Just 1
Just 1
But sometimes, I want to do the inverse. Nothing
represents a success, and Just
a failure.
So if I’ve got a Just
, I won’t got to step 1.
And if I had Nothing at step 0, then I can go to step 1.
Maybe this operator would look like this: >>!
Using x
doesn’t make any sense here (there is no x to be used or of value)
-- Wishfull thinking below
Prelude> Just 0 >>! \x -> Just 1
Nothing
Prelude> Nothing >>! \x -> Just 1
Just 1
Now of course it’s confusing to mix what Just
and Nothing
represent, and it may be a better idea to convert the types so that Just
always represents the happy path. Or use better type names altogether.
But still, I’m wondering if, at a high level, what I’m describing exists and has a name?