Merge pull request #19165 from hochgi/hochgi-unfold-docs-fixes
=str fixing documentation for PR #19143
This commit is contained in:
commit
08d0f2290d
2 changed files with 15 additions and 15 deletions
|
|
@ -172,20 +172,20 @@ object Source {
|
||||||
new Source(scaladsl.Source.repeat(element))
|
new Source(scaladsl.Source.repeat(element))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create a `Source` that will unfold a value of type `S` into
|
* Create a `Source` that will unfold a value of type `S` into
|
||||||
* a pair of the next state `S` and output elements of type `E`.
|
* a pair of the next state `S` and output elements of type `E`.
|
||||||
*/
|
*/
|
||||||
def unfold[S, E](s: S, f: function.Function[S, Option[(S, E)]]): Source[E, Unit] =
|
def unfold[S, E](s: S, f: function.Function[S, Option[(S, E)]]): Source[E, Unit] =
|
||||||
new Source(scaladsl.Source.unfold(s)((s: S) ⇒ f.apply(s)))
|
new Source(scaladsl.Source.unfold(s)((s: S) ⇒ f.apply(s)))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* same as unfold, but uses an async function to generate the next state-element tuple.
|
* Same as [[unfold]], but uses an async function to generate the next state-element tuple.
|
||||||
*/
|
*/
|
||||||
def unfoldAsync[S, E](s: S, f: function.Function[S, Future[Option[(S, E)]]]): Source[E, Unit] =
|
def unfoldAsync[S, E](s: S, f: function.Function[S, Future[Option[(S, E)]]]): Source[E, Unit] =
|
||||||
new Source(scaladsl.Source.unfoldAsync(s)((s: S) ⇒ f.apply(s)))
|
new Source(scaladsl.Source.unfoldAsync(s)((s: S) ⇒ f.apply(s)))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* simpler unfold, for infinite sequences.
|
* Simpler [[unfold]], for infinite sequences.
|
||||||
*/
|
*/
|
||||||
def unfoldInf[S, E](s: S, f: function.Function[S, (S, E)]): Source[E, Unit] = {
|
def unfoldInf[S, E](s: S, f: function.Function[S, (S, E)]): Source[E, Unit] = {
|
||||||
new Source(scaladsl.Source.unfoldInf(s)((s: S) ⇒ f.apply(s)))
|
new Source(scaladsl.Source.unfoldInf(s)((s: S) ⇒ f.apply(s)))
|
||||||
|
|
|
||||||
|
|
@ -245,15 +245,15 @@ object Source {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create a `Source` that will unfold a value of type `S` into
|
* Create a `Source` that will unfold a value of type `S` into
|
||||||
* a pair of the next state `S` and output elements of type `E`.
|
* a pair of the next state `S` and output elements of type `E`.
|
||||||
*
|
*
|
||||||
* for example, all the fibonacci numbers under 10M:
|
* For example, all the Fibonacci numbers under 10M:
|
||||||
*
|
*
|
||||||
* {{{
|
* {{{
|
||||||
* Source.unfold(0 → 1){
|
* Source.unfold(0 → 1) {
|
||||||
* case (a,_) if a > 10000000 ⇒ None
|
* case (a, _) if a > 10000000 ⇒ None
|
||||||
* case (a,b) ⇒ Some((b → (a + b)) → a)
|
* case (a, b) ⇒ Some((b → (a + b)) → a)
|
||||||
* }
|
* }
|
||||||
* }}}
|
* }}}
|
||||||
*/
|
*/
|
||||||
|
|
@ -261,14 +261,14 @@ object Source {
|
||||||
Source.fromGraph(new Unfold(s, f)).withAttributes(DefaultAttributes.unfold)
|
Source.fromGraph(new Unfold(s, f)).withAttributes(DefaultAttributes.unfold)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* same as unfold, but uses an async function to generate the next state-element tuple.
|
* Same as [[unfold]], but uses an async function to generate the next state-element tuple.
|
||||||
*
|
*
|
||||||
* async fibonacci example:
|
* async fibonacci example:
|
||||||
*
|
*
|
||||||
* {{{
|
* {{{
|
||||||
* Source.unfoldAsync(0 → 1){
|
* Source.unfoldAsync(0 → 1) {
|
||||||
* case (a,_) if a > 10000000 ⇒ Future.successful(None)
|
* case (a, _) if a > 10000000 ⇒ Future.successful(None)
|
||||||
* case (a,b) ⇒ Future{
|
* case (a, b) ⇒ Future{
|
||||||
* Thread.sleep(1000)
|
* Thread.sleep(1000)
|
||||||
* Some((b → (a + b)) → a)
|
* Some((b → (a + b)) → a)
|
||||||
* }
|
* }
|
||||||
|
|
@ -279,11 +279,11 @@ object Source {
|
||||||
Source.fromGraph(new UnfoldAsync(s, f)).withAttributes(DefaultAttributes.unfoldAsync)
|
Source.fromGraph(new UnfoldAsync(s, f)).withAttributes(DefaultAttributes.unfoldAsync)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* simpler unfold, for infinite sequences.
|
* Simpler [[unfold]], for infinite sequences.
|
||||||
*
|
*
|
||||||
* {{{
|
* {{{
|
||||||
* Source.unfoldInf(0 → 1){
|
* Source.unfoldInf(0 → 1) {
|
||||||
* case (a,b) ⇒ (b → (a + b)) → a
|
* case (a, b) ⇒ (b → (a + b)) → a
|
||||||
* }
|
* }
|
||||||
* }}}
|
* }}}
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue