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

Add Iterant.intersperse #501

Closed
alexandru opened this Issue Jan 7, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@alexandru
Member

alexandru commented Jan 7, 2018

We need an intersperse similar with the one on Observable, with the following description:

sealed abstract class Iterant[F[_], A] {
  // ...

  /** Creates a new stream from the source that will emit a specific `separator`
    * between every pair of elements.
    *
    * @param separator is the separator
    */
  def intersperse(separator: A)(implicit F: Sync[F]): Iterant[F, A]

  /** Creates a new stream from the source that will emit the `start` element
    * followed by the upstream elements paired with the `separator` 
    * and lastly the `end` element.
    *
    * @param start is the first element emitted
    * @param separator is the separator
    * @param end the last element emitted
    */
  def intersperse(start: A, separator: A, end: A)(implicit F: Sync[F]): Iterant[F, A]
@fancywriter

This comment has been minimized.

fancywriter commented Jul 25, 2018

@alexandru, could you please help me to understand how to use it correctly?
I have observable which emits sequence of strings. The sequence is infinite, I want to have ability to stop it manually interactively by user.

I want to use intersperse with start and end. Suppose I have the following sequence of strings: "one", "two", "three", "four", etc... I want to consume only three of them and than stop let's say after timeout of 10 seconds... I don't know at compile-time is will it end on "three" or "four" or later... Suppose on "three".

And I want to write this observable to the text file of the following format:

[
one,
two,
three
]

But if I call cancel on monix task which is the result of observable.consumeWith(???).runAsync, I am getting only

[
one,
two,
three

Looks unfinished. I want to stop observable, not cancel - how to achieve this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment