Comments (5)
I never really thought about using merge that much (just used it 2 days ago for the first time myself). It was mostly intended to be flatMapped into a common value on the next step anyway (like merging the text of a draft with a text that just got typed).
While I would prefer an array of Signals as the argument, this would not be type safe anymore (it would just be an array of signals, but you won't know each of their types).
Maybe you have an idea how to improve that situation?
For your current case if would be possible to specify a merge operation for signals of the same type like merge(signals: [Signal<T>])
.
from interstellar.
I'm wondering if a multiple merge functions that took multiple signals might be better?
merge(a: Signal, b: Signal)
merge(a: Signal, b: Signal, c: Signal)
merge(a: Signal, b: Signal, c: Signal, d: Signal)
etc.
This way you keep type safety and a flat return structure and still support a reasonable number of signals.
In my code i have four signals at once (building up complex UI from two async http calls, a reverse geocode, and a map snapshot image). I could make them serial but they are intrinsically independent of each other.
from interstellar.
This was actually something I ran into immediately when using this library.
I mainly use Interstellar for form validation. Every form gets its own signal.
They all have to compose somehow to a main signal which holds a value that represents if all forms in certain view are valid. As a quick solution to this problem I came up with a function:
func combineSignals<T>(signals: [Signal<T>], f: (T,T)-> T) -> Signal<T> {
return signals.dropFirst().reduce(signals.first!){ $0.merge($1).map { f($0) }
}
}
It takes an array of signals and a function which 'merges' both values of a tuple into one.
Although this is very specific to my use case, it'll probably a good idea to somehow generalize this in version 2.0.
Maybe implement the transducers protocol?
from interstellar.
If all signals do have the same type, it would be possible to define a merge function like this:
extension Signal {
public class func combine<T>(signals: [Signal<T>]) -> Signal<[T]>
}
from interstellar.
I would also be quite interested in such a function 👍
from interstellar.
Related Issues (20)
- Signal could be struct HOT 2
- Adding Signal update(f: T? -> T) HOT 5
- Interstellar 2.0 HOT 18
- Debounce using GCD? HOT 1
- Yosemite support HOT 5
- Memory leak when map'ing signals HOT 4
- More complex unsubscription in v2 HOT 5
- Possible data race in function `subscribe`
- Not sure about how `debounce` works HOT 2
- Swift 3 version HOT 2
- Missing comma in .podspec file
- Question regarding Thread class HOT 2
- global(qos:) only available on OSX 10.10 HOT 1
- Debounce doesn't deliver last call to update
- Feature Request: API for cancelling underlying async task HOT 5
- Using Queue with observable, maybe race condition? HOT 1
- Filter HOT 3
- Updating observable's value without triggering update HOT 1
- Zero-Knowledge Disposal HOT 5
- Swift's 5 Result type HOT 5
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 interstellar.