Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equivalent to Combine's prepend operator #323

Open
Mika5652 opened this issue Jul 17, 2024 · 2 comments
Open

Equivalent to Combine's prepend operator #323

Mika5652 opened this issue Jul 17, 2024 · 2 comments

Comments

@Mika5652
Copy link

Hi there, I was looking for some equivalent to Combine's prepend operator but I didn't find anything. Is there any plan to introduce this feature into the structured concurrency world? Thanks!

@pyrtsa
Copy link

pyrtsa commented Jul 17, 2024

You could use the chain(_:_:) free function for this, in fact see the first example on the documentation page where a preamble of 3 elements is prepended to another async sequence.

@Mika5652
Copy link
Author

Mika5652 commented Jul 17, 2024

@pyrtsa Seems like this chain(_:_:) replaces the prepend operator only partly, because prepend in Combine can be used in any part of the chain.

For instance:

struct Foo {
  let bar: String
}

let subject = PassthroughSubject<Foo, Never>()

subject
  .prepend(Foo(bar: "bar"))
  .map(\.bar)
  .prepend("foo")
...

I don't know if this is possible with the chain, but I will try it and maybe it fits my needs.

Thanks for the fast response anyway!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants