Skip to content

Unit is not inferred as INothing #2721

Answered by mpilquist
Fristi asked this question in Q&A
Discussion options

You must be logged in to vote

Use the .drain method on Stream to discard those units. For example:

val p: Pipe[F, Byte, Unit] = ???
val q: Pipe[F, Byte, Nothing] = p.andThen(_.drain)

That discarding has to be manual. To see why, consider this program:

val s: Stream[Pure, Unit] = Stream(1, 2, 3).as(())
val s2: Stream[Pure, Int] = Stream(4, 5, 6)
val s3 = s ++ s2

What's the type of s3 here? It's a Stream[Pure, AnyVal] because AnyVal is the least upper bound of Unit and Int.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Fristi
Comment options

Answer selected by Fristi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants