Skip to content

Commit 3a614a4

Browse files
committed
docs: improve Flow documentation
1 parent d5b4f09 commit 3a614a4

File tree

1 file changed

+8
-8
lines changed
  • commons/src/main/scala/io/github/tassiLuca/dse/pimping

1 file changed

+8
-8
lines changed

commons/src/main/scala/io/github/tassiLuca/dse/pimping/Flow.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ import scala.reflect.ClassTag
1010
import scala.util.boundary.break
1111
import scala.util.{Failure, Success, Try, boundary}
1212

13-
/** An asynchronous cold data stream that emits values, inspired to Kotlin Flows. */
13+
/** A cold stream of asynchronously computed values, inspired to Kotlin Flows. */
1414
trait Flow[+T]:
1515

16-
/** Start the flowing of data which can be collected reacting through the given [[collector]] function. */
16+
/** Start the flowing of data that can be collected reacting through the given [[collector]] function. */
1717
def collect(collector: Try[T] => Unit)(using Async, AsyncOperations): Unit
1818

1919
/** An interface modeling an entity capable of [[emit]]ting [[Flow]]able values. */
2020
trait FlowCollector[-T]:
2121

22-
/** Emits a value to the flow. */
22+
/** Emit a value to the flow. */
2323
def emit(value: T)(using Async): Unit
2424

2525
object Flow:
2626

27-
/** Creates a new asynchronous cold [[Flow]] from the given [[body]].
27+
/** Create a new asynchronous cold [[Flow]] from the given [[body]].
2828
* Since it is cold, it starts emitting values only when the [[Flow.collect]] method is called.
29-
* To emit a value use the [[FlowCollector]] given instance.
29+
* To emit a value use the [[FlowCollector]] given instance with `it.emit(value)`.
3030
*/
3131
def apply[T](body: (it: FlowCollector[T]) ?=> Unit): Flow[T] =
3232
val flow = FlowImpl[T]()
@@ -52,7 +52,7 @@ object Flow:
5252
// Ensure to leave the synchronized block after the task has been initialized
5353
// with the correct channel instance.
5454
sync.acquire()
55-
myChannel.foreach(t => collector(t))
55+
myChannel.foreach(collector)
5656

5757
object FlowOps:
5858

@@ -64,14 +64,14 @@ object FlowOps:
6464
catchFailure(collector):
6565
flow.collect(item => collector(Success(f(item.get))))
6666

67-
/** @return a new [[Flow]] whose values are created by flattening the flows generated
67+
/** @return a new [[Flow]] whose values are emitted by flattening the flows generated
6868
* by the given function [[f]] applied to each emitted value of this.
6969
*/
7070
def flatMap[R](f: T => Flow[R]): Flow[R] = new Flow[R]:
7171
override def collect(collector: Try[R] => Unit)(using Async, AsyncOperations): Unit =
7272
catchFailure(collector):
7373
flow.collect(item => f(item.get).collect(x => collector(Success(x.get))))
74-
74+
7575
def toSeq(using Async, AsyncOperations): Try[Seq[T]] = boundary:
7676
var result = Seq.empty[T]
7777
flow.collect:

0 commit comments

Comments
 (0)