Skip to content

Commit c9be9d7

Browse files
committed
Update to new combinators
1 parent 87af702 commit c9be9d7

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed

examples/stdlib/stream/first.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
1
22
true
3-
MissingValue: code in first did not emit any values
3+
MissingValue
Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
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

66
def 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
}

libraries/common/stream.effekt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff 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

351351
namespace returning {
352352

0 commit comments

Comments
 (0)