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

Relax constraint for Signal.constant #3032

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions core/shared/src/main/scala/fs2/concurrent/Signal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package fs2
package concurrent

import cats.data.OptionT
import cats.effect.kernel.{Concurrent, Deferred, Ref}
import cats.effect.kernel.{Concurrent, Deferred, Ref, Spawn}
import cats.effect.std.MapRef
import cats.syntax.all._
import cats.{Applicative, Functor, Invariant, Monad}
Expand Down Expand Up @@ -112,13 +112,16 @@ trait Signal[F[_], A] {
}

object Signal extends SignalInstances {
def constant[F[_], A](a: A)(implicit F: Concurrent[F]): Signal[F, A] =
def constant[F[_], A](a: A)(implicit F: Spawn[F]): Signal[F, A] =
new Signal[F, A] {
def get: F[A] = F.pure(a)
def continuous: Stream[Pure, A] = Stream.constant(a)
def discrete: Stream[F, A] = Stream(a) ++ Stream.never
}

@deprecated("Use overload with Spawn constraint", "3.4.0")
def constant[F[_], A](a: A, F: Concurrent[F]): Signal[F, A] = constant(a)(F)

def mapped[F[_]: Functor, A, B](fa: Signal[F, A])(f: A => B): Signal[F, B] =
new Signal[F, B] {
def continuous: Stream[F, B] = fa.continuous.map(f)
Expand Down