Skip to content

Commit

Permalink
Align docs and tests
Browse files Browse the repository at this point in the history
Add implied import entry to sidebar
  • Loading branch information
odersky committed Feb 8, 2019
1 parent 16cb974 commit 12ded36
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
8 changes: 4 additions & 4 deletions docs/docs/reference/contextual/conversions.md
Expand Up @@ -54,15 +54,15 @@ object Completions {
// these always come with CompletionArg
// They can be invoked explicitly, e.g.
//
// CompletionArg.from(statusCode)
// CompletionArg.fromStatusCode(statusCode)

implied from for Conversion[String, CompletionArg] {
implied fromString for Conversion[String, CompletionArg] {
def apply(s: String) = CompletionArg.Error(s)
}
implied from for Conversion[Future[HttpResponse], CompletionArg] {
implied fromFuture for Conversion[Future[HttpResponse], CompletionArg] {
def apply(f: Future[HttpResponse]) = CompletionArg.Response(f)
}
implied from for Conversion[Future[StatusCode], CompletionArg] {
implied fromStatusCode for Conversion[Future[StatusCode], CompletionArg] {
def apply(code: Future[StatusCode]) = CompletionArg.Status(code)
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/reference/contextual/query-types.md
Expand Up @@ -133,7 +133,7 @@ object PostConditions {
}

object Test {
import PostConditions.ensuring
import PostConditions.{ensuring, result}
val s = List(1, 2, 3).sum.ensuring(result == 6)
}
```
Expand Down
2 changes: 2 additions & 0 deletions docs/sidebar.yml
Expand Up @@ -47,6 +47,8 @@ sidebar:
url: docs/reference/contextual/inferable-params.html
- title: Context Bounds
url: docs/reference/contextual/context-bounds.html
- title: Implied Imports
url: docs/reference/contextual/import-implied.html
- title: Extension Methods
url: docs/reference/contextual/extension-methods.html
- title: Implementing Typeclasses
Expand Down
21 changes: 21 additions & 0 deletions tests/pos/postconditions.scala
@@ -0,0 +1,21 @@
object PostConditions {
opaque type WrappedResult[T] = T

private object WrappedResult {
def wrap[T](x: T): WrappedResult[T] = x
def unwrap[T](x: WrappedResult[T]): T = x
}

def result[T] given (r: WrappedResult[T]): T = WrappedResult.unwrap(r)

def (x: T) ensuring [T](condition: given WrappedResult[T] => Boolean): T = {
implied for WrappedResult[T] = WrappedResult.wrap(x)
assert(condition)
x
}
}

object Test {
import PostConditions.{ensuring, result}
val s = List(1, 2, 3).sum.ensuring(result == 6)
}
29 changes: 18 additions & 11 deletions tests/pos/reference/instances.scala
Expand Up @@ -266,22 +266,29 @@ object Completions {
case Response(f: Future[HttpResponse])
case Status(code: Future[StatusCode])
}
object CompletionArg {

// conversions defining the possible arguments to pass to `complete`
// these always come with CompletionArg
// They can be invoked explicitly, e.g.
//
// CompletionArg.from(statusCode)

implied fromString for Conversion[String, CompletionArg] {
def apply(s: String) = CompletionArg.Error(s)
}
implied fromFuture for Conversion[Future[HttpResponse], CompletionArg] {
def apply(f: Future[HttpResponse]) = CompletionArg.Response(f)
}
implied fromStatusCode for Conversion[Future[StatusCode], CompletionArg] {
def apply(code: Future[StatusCode]) = CompletionArg.Status(code)
}
}
import CompletionArg._

def complete[T](arg: CompletionArg) = arg match {
case Error(s) => ???
case Response(f) => ???
case Status(code) => ???
}

// conversions defining the possible arguments to pass to `complete`
implied stringArg for Conversion[String, CompletionArg] {
def apply(s: String) = CompletionArg.Error(s)
}
implied responseArg for Conversion[Future[HttpResponse], CompletionArg] {
def apply(f: Future[HttpResponse]) = CompletionArg.Response(f)
}
implied statusArg for Conversion[Future[StatusCode], CompletionArg] {
def apply(code: Future[StatusCode]) = CompletionArg.Status(code)
}
}

0 comments on commit 12ded36

Please sign in to comment.