Skip to content

Commit 0093f94

Browse files
authored
Merge pull request scala-js#55 from ShapelessCat/fix-links-and-change-names
Fix links and change names
2 parents 049db25 + 88d3f9b commit 0093f94

13 files changed

+34
-48
lines changed

src/main/scala/ContextQueries.scala renamed to src/main/scala/ContextFunctions.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
21
import scala.concurrent.{ExecutionContext, Future}
32
import scala.util.Try
43

54
/**
6-
* Context Queries:
7-
* - http://dotty.epfl.ch/docs/reference/contextual/query-types.html,
5+
* Context Functions:
6+
* - https://dotty.epfl.ch/docs/reference/contextual/context-functions.html
87
* - https://www.scala-lang.org/blog/2016/12/07/implicit-function-types.html
98
*/
10-
object ContextQueries /* Formerly known as Implicit Function Types */ {
9+
object ContextFunctions {
1110

1211
object context {
1312
// type alias Contextual
@@ -21,10 +20,10 @@ object ContextQueries /* Formerly known as Implicit Function Types */ {
2120

2221
object parse {
2322

24-
type Parseable[T] = ImpliedInstances.StringParser[T] ?=> Try[T]
23+
type Parseable[T] = GivenInstances.StringParser[T] ?=> Try[T]
2524

2625
def sumStrings(x: String, y: String): Parseable[Int] = {
27-
val parser = implicitly[ImpliedInstances.StringParser[Int]]
26+
val parser = summon[GivenInstances.StringParser[Int]]
2827
val tryA = parser.parse(x)
2928
val tryB = parser.parse(y)
3029

@@ -36,7 +35,6 @@ object ContextQueries /* Formerly known as Implicit Function Types */ {
3635
}
3736

3837
def test: Unit = {
39-
4038
import ExecutionContext.Implicits.global
4139
context.asyncSum(3, 4).foreach(println)
4240
context.asyncMult(3, 4).foreach(println)

src/main/scala/Conversion.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,4 @@ object Conversion {
3232
println(convert(new IntWrapper(42)))
3333
}
3434

35-
36-
3735
}

src/main/scala/EnumTypes.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ object EnumTypes {
2424
}
2525

2626
def test: Unit = {
27-
2827
val emptyList = ListEnum.Empty
2928
val list = ListEnum.Cons(1, ListEnum.Cons(2, ListEnum.Cons(3, ListEnum.Empty)))
3029
println(emptyList)

src/main/scala/ImpliedInstances.scala renamed to src/main/scala/GivenInstances.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import scala.util.{Success, Try}
22

33
/**
4-
* Implied Instances:
5-
* - https://dotty.epfl.ch/docs/reference/contextual/instance-defs.html
4+
* Implied Instances: https://dotty.epfl.ch/docs/reference/contextual/givens.html
65
*/
7-
object ImpliedInstances {
6+
object GivenInstances {
87

98
sealed trait StringParser[A] {
109
def parse(s: String): Try[A]
@@ -30,10 +29,11 @@ object ImpliedInstances {
3029
}
3130

3231
def test: Unit = {
33-
println(implicitly[StringParser[Option[Int]]].parse("21"))
34-
println(implicitly[StringParser[Option[Int]]].parse(""))
35-
println(implicitly[StringParser[Option[Int]]].parse("21a"))
32+
println(summon[StringParser[Option[Int]]].parse("21"))
33+
println(summon[StringParser[Option[Int]]].parse(""))
34+
println(summon[StringParser[Option[Int]]].parse("21a"))
3635

37-
println(implicitly[StringParser[Option[Int]]](StringParser.optionParser[Int]).parse("42"))
36+
println(summon[StringParser[Option[Int]]](using StringParser.optionParser[Int]).parse("42"))
3837
}
38+
3939
}

src/main/scala/IntersectionTypes.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ object IntersectionTypes {
2121
}
2222

2323
def test: Unit = {
24-
2524
def euclideanDistance(p1: X & Y, p2: X & Y) = {
2625
Math.sqrt(Math.pow(p2.y - p1.y, 2) + Math.pow(p2.x - p1.x, 2))
2726
}
2827

2928
val p1: P = Point(3, 4)
3029
val p2: PP = Point(6, 8)
3130
println(euclideanDistance(p1, p2))
32-
3331
}
32+
3433
}

src/main/scala/Main.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
object Main {
32

43
def main(args: Array[String]): Unit = {
@@ -7,9 +6,9 @@ object Main {
76

87
runExample("Enum Types")(EnumTypes.test)
98

10-
runExample("Context Queries")(ContextQueries.test)
9+
runExample("Context Functions")(ContextFunctions.test)
1110

12-
runExample("Implied Instances")(ImpliedInstances.test)
11+
runExample("Given Instances")(GivenInstances.test)
1312

1413
runExample("Conversion")(Conversion.test)
1514

@@ -21,7 +20,7 @@ object Main {
2120

2221
runExample("Multiversal Equality")(MultiversalEquality.test)
2322

24-
runExample("Auto Param Tupling")(AutoParamTupling.test)
23+
runExample("Parameter Untupling")(ParameterUntupling.test)
2524

2625
runExample("Structural Types")(StructuralTypes.test)
2726

src/main/scala/MultiversalEquality.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import scala.language.strictEquality
77
object MultiversalEquality {
88

99
def test: Unit = {
10-
1110
// Values of types Int and String cannot be compared with == or !=,
1211
// unless we add the derived delegate instance like:
1312
given CanEqual[Int, String] = CanEqual.derived
@@ -35,4 +34,5 @@ object MultiversalEquality {
3534
println(a != b)
3635
println(b == a)
3736
}
37+
3838
}

src/main/scala/AutoParamTupling.scala renamed to src/main/scala/ParameterUntupling.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
21
/**
3-
* Automatic Tupling of Function Params: https://dotty.epfl.ch/docs/reference/other-new-features/auto-parameter-tupling.html
2+
* Parameter Untupling: https://dotty.epfl.ch/docs/reference/other-new-features/parameter-untupling.html
43
*/
5-
object AutoParamTupling {
4+
object ParameterUntupling {
65

76
def test: Unit = {
8-
97
/**
108
* In order to get thread safety, you need to put @volatile before lazy vals.
119
* https://dotty.epfl.ch/docs/reference/changed-features/lazy-vals.html
@@ -19,6 +17,6 @@ object AutoParamTupling {
1917
* Consider a pattern matching anonymous function, `{ case (s, i) => ... }`
2018
*/
2119
xs.zipWithIndex.map((s, i) => println(s"$i: $s"))
22-
2320
}
21+
2422
}

src/main/scala/PatternMatching.scala

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/**
32
* Pattern Matching: https://dotty.epfl.ch/docs/reference/changed-features/pattern-matching.html
43
*/
@@ -59,19 +58,17 @@ object PatternMatching {
5958
}
6059

6160
def test: Unit = {
62-
6361
import booleanPattern._
6462

6563
"even" match {
6664
case s @ Even() => println(s"$s has an even number of characters")
67-
case s => println(s"$s has an odd number of characters")
65+
case s => println(s"$s has an odd number of characters")
6866
}
6967

70-
// http://dotty.epfl.ch/docs/reference/changed/vararg-patterns.html
68+
// http://dotty.epfl.ch/docs/reference/changed-features/vararg-patterns.html
7169
def containsConsecutive(list: List[Int]): Boolean = list match {
72-
case List(a, b, xs: _ *) => if (a == b) true else containsConsecutive(b :: xs.toList)
73-
case List(a, _ : _*) => false
74-
case Nil => false
70+
case List(a, b, xs: _*) => if (a == b) true else containsConsecutive(b :: xs.toList)
71+
case Nil | List(_, _: _*) => false
7572
}
7673

7774
println(containsConsecutive(List(1, 2, 3, 4, 5)))
@@ -86,7 +83,7 @@ object PatternMatching {
8683

8784
def greet(fullName: String) = fullName match {
8885
case Names(lastName, firstName, _: _*) => "Good morning, " + firstName + " " + lastName + "!"
89-
case _ => "Welcome! Please make sure to fill in your name!"
86+
case _ => "Welcome! Please make sure to fill in your name!"
9087
}
9188

9289
println(greet("Alan Turing"))
@@ -96,8 +93,8 @@ object PatternMatching {
9693
import namePattern._
9794
"alice" match {
9895
case Name(n) => println(s"name is $n")
99-
case _ => println("empty name")
96+
case _ => println("empty name")
10097
}
101-
10298
}
99+
103100
}

src/main/scala/StructuralTypes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/**
32
* Structural Types: https://dotty.epfl.ch/docs/reference/changed-features/structural-types.html
43
*/
@@ -25,4 +24,5 @@ object StructuralTypes {
2524
// age field is java.util.NoSuchElementException: None.get
2625
//println(invalidPerson.age)
2726
}
27+
2828
}

src/main/scala/TraitParams.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ object TraitParams {
1111
private def printMessages(msgs: (A | B)*) = println(msgs.map(_.msg).mkString(" "))
1212

1313
def test: Unit = {
14-
1514
printMessages(new A, new B)
1615

1716
// Sanity check the classpath: this won't run if the dotty jar is not present.
1817
val x: Int => Int = z => z
1918
x(1)
2019
}
20+
2121
}

src/main/scala/TypeLambdas.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ object TypeLambdas {
88
type Tuple = [X] =>> (X, X)
99

1010
def test: Unit = {
11-
1211
val m: T[String, Int] = Map(1 -> "1")
1312
println(m)
1413

src/main/scala/UnionTypes.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object UnionTypes {
1111
type DivisionResult = DivisionByZero | Success
1212

1313
sealed trait List[+A]
14-
final case class Empty() extends List[Nothing]
14+
case object Empty extends List[Nothing]
1515
final case class Cons[+A](h: A, t: List[A]) extends List[A]
1616

1717
private def safeDivide(a: Double, b: Double): DivisionResult = {
@@ -20,11 +20,10 @@ object UnionTypes {
2020

2121
private def either(division: Division) = division match {
2222
case DivisionByZero(m) => Left(m)
23-
case Success(d) => Right(d)
23+
case Success(d) => Right(d)
2424
}
2525

2626
def test: Unit = {
27-
2827
val divisionResultSuccess: DivisionResult = safeDivide(4, 2)
2928

3029
// commutative
@@ -36,10 +35,10 @@ object UnionTypes {
3635
// calling `either` function with union typed value.
3736
println(either(divisionResultFailure))
3837

39-
val list: Cons[Int] | Empty = Cons(1, Cons(2, Cons(3, Empty())))
40-
val emptyList: Empty | Cons[Any] = Empty()
38+
val list: Cons[Int] | Empty.type = Cons(1, Cons(2, Cons(3, Empty)))
39+
val emptyList: Empty.type | Cons[Any] = Empty
4140
println(list)
4241
println(emptyList)
43-
4442
}
43+
4544
}

0 commit comments

Comments
 (0)