ctietze,
@ctietze@mastodon.social avatar

I have a question!

Never wrote my own Publisher. Always combined others.

But this once, I believe that it would be nicer to have a struct instead of a function.

So I wrote a Combine.Publishers.Either type, but now I'm not sure if that's all there is, really.

https://gist.github.com/DivineDominion/de85d2dc3d42f6ebfe29f1d35a3c7da3

Feedback very much appreciated! 🙏

mattiem,
@mattiem@mastodon.social avatar

@ctietze I dont know enough to provide meaningful feedback here. But it would be cool to understand the problem this addresses!

ctietze,
@ctietze@mastodon.social avatar

@mattiem Terrible mouse art, sorry :)

If I had learned my computer architecture better, I could tell you how these things are called.

It's a switch to select which source's signals to ignore and which to use. Here: E1 and E2.

mattiem,
@mattiem@mastodon.social avatar

@ctietze I think I understand 😅

But I don’t think I can give you too much helpful feedback. Other than if the API is helpful/nice-looking then it’s good!

ctietze,
@ctietze@mastodon.social avatar

@mattiem In our concrete use case:

A and B both emit two signals (have two publishers) of the same kind. A and B describe different sources for these signals.

And the user can change which to use independently. Signal 1 of A or Signal 1 of B? And Signal 2 of A or Signal 2 of B?

The 'eithers' then represent a "Signal 1 of either A or B" and "Signal 2 of either A or B".

(It's about audio input (Signal 1) and output (2) device selection based on system default (A) or custom choice (B).)

mattiem,
@mattiem@mastodon.social avatar

@ctietze Sorry I’m deep in my own issue right now and struggling to fully follow.

But it sounds like you’ve got this!

ctietze,
@ctietze@mastodon.social avatar

@mattiem Yeah let's hope so :)

What are you up to?

mattiem,
@mattiem@mastodon.social avatar

@ctietze I spent yesterday trying to solve a problem using a Fancy Data Structure and failing. Trying again today.

ctietze,
@ctietze@mastodon.social avatar

@mattiem Is FancyDataStructure the opposite of SimpleDataStructure, what people used to like? :)

mattiem,
@mattiem@mastodon.social avatar

@ctietze it is definitely the opposite of simple

5sw,
@5sw@darmstadt.social avatar

@ctietze @mattiem
Depends on what kind of publishers A and B provide, but sounds like this might be a job for switchToLatest instead. With that the subscription to the currently unused publisher is cancelled.

ctietze,
@ctietze@mastodon.social avatar

@5sw @mattiem I am working on that, too, to provide more control.

We actually do want to immediately replay the last known value after toggling the switch left/right.

But a base implementation should rather not do that and make replaying the responsibility of the A/B publishers 🤔

icanzilb,
@icanzilb@mastodon.social avatar

@ctietze @mattiem sounds like a combineLatest + compactMap to me? The first takes all source values + the user selection, the latter emits only the source value ones for the selected source?

5sw,
@5sw@darmstadt.social avatar

@ctietze looks reasonable. I‘d try to avoid the AnyPublisher in there, though. This means having to take the upstream publisher types as the generic parameters.

ctietze,
@ctietze@mastodon.social avatar

@5sw You really mean the whole of:

Publishers.Map<Publishers.CombineLatest3<S, L, R>, Either<Left, Right>>

?

The S,L,R part is not representable outside of the initializer.

Why would you avoid that?

5sw,
@5sw@darmstadt.social avatar

@ctietze I mean like this:

struct _EitherPublisher<L: Publisher, R: Publisher, S: Publisher>: Publisher where L.Failure == R.Failure, L.Failure == S.Failure, S.Output == Select

This is how Apple implements their operator publishers and avoids having to use AnyPublisher in there

ctietze,
@ctietze@mastodon.social avatar

@5sw Need to move the Select enum out of the publisher for this to work. Then this does the job. Neat, thank you!

  • All
  • Subscribed
  • Moderated
  • Favorites
  • swift
  • kavyap
  • thenastyranch
  • GTA5RPClips
  • tester
  • InstantRegret
  • DreamBathrooms
  • ngwrru68w68
  • magazineikmin
  • everett
  • Youngstown
  • mdbf
  • slotface
  • rosin
  • cisconetworking
  • megavids
  • khanakhh
  • normalnudes
  • osvaldo12
  • cubers
  • tacticalgear
  • Durango
  • ethstaker
  • modclub
  • anitta
  • provamag3
  • Leos
  • JUstTest
  • lostlight
  • All magazines