Skip to content

Commit 12ded36

Browse files
committed
Align docs and tests
Add implied import entry to sidebar
1 parent 16cb974 commit 12ded36

File tree

5 files changed

+46
-16
lines changed

5 files changed

+46
-16
lines changed

docs/docs/reference/contextual/conversions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ object Completions {
5454
// these always come with CompletionArg
5555
// They can be invoked explicitly, e.g.
5656
//
57-
// CompletionArg.from(statusCode)
57+
// CompletionArg.fromStatusCode(statusCode)
5858

59-
implied from for Conversion[String, CompletionArg] {
59+
implied fromString for Conversion[String, CompletionArg] {
6060
def apply(s: String) = CompletionArg.Error(s)
6161
}
62-
implied from for Conversion[Future[HttpResponse], CompletionArg] {
62+
implied fromFuture for Conversion[Future[HttpResponse], CompletionArg] {
6363
def apply(f: Future[HttpResponse]) = CompletionArg.Response(f)
6464
}
65-
implied from for Conversion[Future[StatusCode], CompletionArg] {
65+
implied fromStatusCode for Conversion[Future[StatusCode], CompletionArg] {
6666
def apply(code: Future[StatusCode]) = CompletionArg.Status(code)
6767
}
6868
}

docs/docs/reference/contextual/query-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ object PostConditions {
133133
}
134134

135135
object Test {
136-
import PostConditions.ensuring
136+
import PostConditions.{ensuring, result}
137137
val s = List(1, 2, 3).sum.ensuring(result == 6)
138138
}
139139
```

docs/sidebar.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ sidebar:
4747
url: docs/reference/contextual/inferable-params.html
4848
- title: Context Bounds
4949
url: docs/reference/contextual/context-bounds.html
50+
- title: Implied Imports
51+
url: docs/reference/contextual/import-implied.html
5052
- title: Extension Methods
5153
url: docs/reference/contextual/extension-methods.html
5254
- title: Implementing Typeclasses

tests/pos/postconditions.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
object PostConditions {
2+
opaque type WrappedResult[T] = T
3+
4+
private object WrappedResult {
5+
def wrap[T](x: T): WrappedResult[T] = x
6+
def unwrap[T](x: WrappedResult[T]): T = x
7+
}
8+
9+
def result[T] given (r: WrappedResult[T]): T = WrappedResult.unwrap(r)
10+
11+
def (x: T) ensuring [T](condition: given WrappedResult[T] => Boolean): T = {
12+
implied for WrappedResult[T] = WrappedResult.wrap(x)
13+
assert(condition)
14+
x
15+
}
16+
}
17+
18+
object Test {
19+
import PostConditions.{ensuring, result}
20+
val s = List(1, 2, 3).sum.ensuring(result == 6)
21+
}

tests/pos/reference/instances.scala

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,22 +266,29 @@ object Completions {
266266
case Response(f: Future[HttpResponse])
267267
case Status(code: Future[StatusCode])
268268
}
269+
object CompletionArg {
270+
271+
// conversions defining the possible arguments to pass to `complete`
272+
// these always come with CompletionArg
273+
// They can be invoked explicitly, e.g.
274+
//
275+
// CompletionArg.from(statusCode)
276+
277+
implied fromString for Conversion[String, CompletionArg] {
278+
def apply(s: String) = CompletionArg.Error(s)
279+
}
280+
implied fromFuture for Conversion[Future[HttpResponse], CompletionArg] {
281+
def apply(f: Future[HttpResponse]) = CompletionArg.Response(f)
282+
}
283+
implied fromStatusCode for Conversion[Future[StatusCode], CompletionArg] {
284+
def apply(code: Future[StatusCode]) = CompletionArg.Status(code)
285+
}
286+
}
269287
import CompletionArg._
270288

271289
def complete[T](arg: CompletionArg) = arg match {
272290
case Error(s) => ???
273291
case Response(f) => ???
274292
case Status(code) => ???
275293
}
276-
277-
// conversions defining the possible arguments to pass to `complete`
278-
implied stringArg for Conversion[String, CompletionArg] {
279-
def apply(s: String) = CompletionArg.Error(s)
280-
}
281-
implied responseArg for Conversion[Future[HttpResponse], CompletionArg] {
282-
def apply(f: Future[HttpResponse]) = CompletionArg.Response(f)
283-
}
284-
implied statusArg for Conversion[Future[StatusCode], CompletionArg] {
285-
def apply(code: Future[StatusCode]) = CompletionArg.Status(code)
286-
}
287294
}

0 commit comments

Comments
 (0)