Skip to content

Commit

Permalink
Add non-lazy succeed
Browse files Browse the repository at this point in the history
  • Loading branch information
ioleo committed Aug 10, 2019
1 parent a98a540 commit e18cb07
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
8 changes: 7 additions & 1 deletion streams/shared/src/main/scala/zio/stream/Sink.scala
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,15 @@ object Sink {
final def read1[E, A](e: Option[A] => E)(p: A => Boolean): Sink[E, A, A, A] =
ZSink.read1(e)(p)

/**
* see [[ZSink.succeed]]
*/
final def succeed[B](b: B): Sink[Nothing, Nothing, Any, B] =
ZSink.succeed(b)

@deprecated("use succeed", "1.0.0")
final def succeedLazy[B](b: => B): Sink[Nothing, Nothing, Any, B] =
succeed(a)
succeed(b)

/**
* see [[ZSink.throttleEnforce]]
Expand Down
13 changes: 12 additions & 1 deletion streams/shared/src/main/scala/zio/stream/ZSink.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1295,9 +1295,20 @@ object ZSink extends ZSinkPlatformSpecific {
}
}

/**
* Creates a single-value sink from a value.
*/
final def succeed[B](b: B): ZSink[Any, Nothing, Nothing, Any, B] =
new SinkPure[Nothing, Nothing, Any, B] {
type State = Unit
val initialPure = Step.done((), Chunk.empty)
def stepPure(state: State, a: Any): Step[State, Nothing] = Step.done(state, Chunk.empty)
def extractPure(state: State): Either[Nothing, B] = Right(b)
}

@deprecated("use succeed", "1.0.0")
final def succeedLazy[B](b: => B): ZSink[Any, Nothing, Nothing, Any, B] =
succeed(a)
succeed(b)

/**
* Creates a sink which throttles input elements of type A according to the given bandwidth parameters
Expand Down
8 changes: 7 additions & 1 deletion streams/shared/src/main/scala/zio/stream/ZStreamChunk.scala
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,13 @@ object ZStreamChunk {
final def fromChunks[A](as: Chunk[A]*): StreamChunk[Nothing, A] =
StreamChunkPure(StreamPure.fromIterable(as))

/**
* Creates a `ZStreamChunk` from a chunk
*/
final def succeed[A](as: Chunk[A]): StreamChunk[Nothing, A] =
StreamChunkPure(StreamPure.succeed(as))

@deprecated("use succeed", "1.0.0")
final def succeedLazy[A](as: => Chunk[A]): StreamChunk[Nothing, A] =
succeed(a)
succeed(as)
}

0 comments on commit e18cb07

Please sign in to comment.