File tree Expand file tree Collapse file tree 3 files changed +11
-23
lines changed
Expand file tree Collapse file tree 3 files changed +11
-23
lines changed Original file line number Diff line number Diff line change 111
22true
3- MissingValue: code in first did not emit any values
3+ MissingValue
Original file line number Diff line number Diff line change 1- def printResult [T](result: Result[T, MissingValue ]) { printSuccess: T => Unit } = result match {
2- case Success (value) => printSuccess(value)
3- case Error(err, msg ) => println("MissingValue: " ++ msg )
1+ def printOption [T](option: Option[T ]) { printSuccess: T => Unit } = option match {
2+ case Some (value) => printSuccess(value)
3+ case None( ) => println("MissingValue" )
44}
55
66def main() = {
7- printResult(
8- on[MissingValue].result {
9- stream::first[Int] { [1, 2, 3].each }
10- }
11- ) { x => println(x) }
7+ printOption(optionally { stream::first[Int] { [1, 2, 3].each } }) { x => println(x) }
128
13- printResult(
14- on[MissingValue].result {
15- first[Bool] { do emit(true) }
16- }
17- ) { x => println(x) }
9+ printOption(optionally { first[Bool] { do emit(true) } }) { x => println(x) }
1810
19- printResult(
20- on[MissingValue].result {
21- first[String] { () } // empty stream
22- }
23- ) { x => println(x) }
11+ printOption(optionally { first[String] { () } }) { x => println(x) }
2412}
Original file line number Diff line number Diff line change @@ -339,14 +339,14 @@ def tee[A]{ cons1: { => Unit / emit[A] } => Unit }{ cons2: { => Unit / emit[A] }
339339/// > first[Bool] { do emit(true) }
340340/// true
341341/// > first[String] { () } // empty stream
342- /// <Exception MissingValue: code in first did not emit any values >
342+ /// <fail >
343343/// ```
344- def first[A] { body: => Unit / emit[A] }: A / Exception[MissingValue] =
344+ def first[A] { stream: () => Unit / emit[A] }: A / fail = {
345345 try {
346+ def body(): A = { stream(); do fail() }
346347 body()
347- val r: A = do raise[MissingValue](MissingValue(), "code in first did not emit any values")
348- r
349348 } with emit[A] { a => a }
349+ }
350350
351351namespace returning {
352352
You can’t perform that action at this time.
0 commit comments