Comments (2)
The very first version of reactive-banana provided two functions with different names
union :: Event a -> Event a -> Event a
merge :: Event a -> Event b -> Event (Either a b)
Later, I have dropped the merge
function because it turned out to be way less useful than union
. (That's also why the MonadPlus
and Alternative
classes don't provide something like merge
).
The reason is that its usually more convenient to apply different pattern matches right away instead of building a direct sum first and then deconstructing it again. In other words, the result of merge
is usually used with a pattern match. The prototypical example
either f g (e1 `merge` e2) = (f <$> e1) `union` (g <$> e2)
shows that union
is actually more convenient for this application, since it dispenses with the intermediate Either
type and easily generalizes to severeal unions.
In your example, we have the special situation that the return type is ignored, i.e.
eQuit = () <$ (eWindowClose `merge` eCtrlQ `merge` eSIGINT)
and the pattern match disappears entirely, that's why it looks a bit more convenient. However, using the function
Control.Monad.void :: Functor f => f a -> f ()
you can drop the parentheses and make the whole thing a bit nicer
eQuit = void eWindowClose `union` void eCtrlQ `union` void eSIGINT
I think that this is a good compromise.
Summary
- I'm against changing the type of
union
. - I'm don't like introducing the
merge
function again, because I feel that it clutters the interface. - I think that the
void
function is enough to make your example reasonably nice.
Let me know what you think.
PS: I've changed your post to read newUnion :: FRP f => Event f a -> Event f b -> Event f (Either a b)
because that's what you probably meant.
from reactive-banana.
Oh, silly me; I had assumed that Control.Monad.void
would only work on monads, due to the module name. Yes, I agree with your conclusion; I think this thought was a bit premature.
from reactive-banana.
Related Issues (20)
- Switch from `pqueue` to `psqueues` or `heaps`? HOT 6
- Request: Less restrictive bounds for package deps on hackage HOT 3
- Dynamic event switching results in "*** Exception: thread blocked indefinitely in an MVar operation" deadlock HOT 9
- Add role annotations to `Behavior` and `Event` HOT 2
- Add `Monoid a => Monoid (MomentIO a)` (and `Moment`)
- Add `@>` HOT 3
- Successful evaluation for an undefined network HOT 5
- `reactive-banana` can't be compiled on GHC 9.2 HOT 2
- I created a Matrix channel HOT 8
- An interesting `Applicative`-ish way of combining `Event`s HOT 4
- Add `MonadMoment` instances for all monad transformers in `transformers` HOT 1
- Release 1.3.0.0 HOT 3
- Join Stackage HOT 4
- `Behavior` constantly re-evaluating when caching is expected HOT 4
- Unexpected memory growth HOT 6
- Event handler not seeing early events. HOT 12
- `Behavior`s can hold onto more memory than they need to HOT 2
- Memory leak with dynamic behavior switching HOT 16
- Gloss GUI events not responding HOT 5
- Idea: add a combinator to track when a behavior is a different value HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reactive-banana.