Add parOneOf - #18
Add parOneOf#18
Conversation
| parOneOf | ||
| :: forall a t m f | ||
| . Parallel f m | ||
| => Plus f |
There was a problem hiding this comment.
Is it useful to have Alternative here, since we already have Applicative anyway? Seems like the additional laws might be nice to have.
There was a problem hiding this comment.
I was just providing the minimal set of constraints required to get this to compile.
There was a problem hiding this comment.
Yeah, I guessed so, but I'm wondering if it's helpful to have the generality. We'd need something which has Plus and Applicative but not Alternative. If we assume Alternative, then we get two extra laws that we can use to think about how this function interoperates with <*>.
There was a problem hiding this comment.
If the function doesn't take advantage of those laws, then what does it even mean?
There was a problem hiding this comment.
For example, parOneOf [] <*> x = parOneOf [] if you have Alternative, but not necessarily otherwise. Also parOneOf (xs <> ys) <*> x = (parOneOf xs <*> x) <> (parOneOf ys <*> x) if you have Alternative.
There was a problem hiding this comment.
Right, my point was just that this function only takes advantage of Plus, and if anyone using it needs the additional laws, they can request an Alternative constraint. But that's also like saying functions should be using Bind and Applicative instead of Monad, which is silly. So I'll change it 😛
| -> m Unit | ||
| parSequence_ = parTraverse_ id | ||
|
|
||
| parOneOf |
There was a problem hiding this comment.
Looks good, but could you please add a comment?
|
Addressed feedback and added |
|
I think these kind of functions could really benefit from examples. Is my intuition right here? parOneOf
[ delay 10 (log "A") *> pure (Just "A")
, log "B" *> pure Nothing
]
> prints B
> prints A
> Just "A" |
The reason I'm adding them is so I can have nicer looking examples in the Aff docs. In any case, the behavior of |
|
|
|
Done |
| => Functor t | ||
| => t (m a) | ||
| -> m a | ||
| parOneOf = sequential <<< oneOf <<< map parallel |
There was a problem hiding this comment.
Oh, good catch.
|
FORGOT AN EXPORT HERE TOO |
No description provided.