From d68b50295111fd9a36a07f0e692db2c97ad5a70e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Miguel=20Mej=C3=ADa=20Su=C3=A1rez?= Date: Sat, 12 Dec 2020 15:40:05 -0500 Subject: [PATCH 1/3] Adding more details to one-link answers --- _overviews/FAQ/index.md | 59 ++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/_overviews/FAQ/index.md b/_overviews/FAQ/index.md index e187410b13..541fcbafac 100644 --- a/_overviews/FAQ/index.md +++ b/_overviews/FAQ/index.md @@ -22,7 +22,7 @@ over again in Scala chat rooms and forums. ### Where can I ask Scala questions? -see our [Community page](https://scala-lang.org/community/) +See our [Community page](https://scala-lang.org/community/). ### Should I learn Scala 2, or Scala 3? @@ -73,31 +73,38 @@ answers here, I think it's better to provide only short answers and links. if something needs more space to explain, there should be official documentation that addresses it, not just an FAQ answer --> -[answer]({{ site.baseurl }}/tutorials/FAQ/initialization-order.html) +See [this]({{ site.baseurl }}/tutorials/FAQ/initialization-order.html). ### Which type of collection should I choose? -see the [Scala 2.13 Collections Guide](https://docs.scala-lang.org/overviews/collections-2.13/introduction.html) +See the [Scala 2.13 Collections Guide](https://docs.scala-lang.org/overviews/collections-2.13/introduction.html). ### What are context bounds (`[T : Foo]`)? -[answer on Stack Overflow](https://stackoverflow.com/a/4467012) +Basically is sugar syntax for an `implicit` argument of type `Foo[T]`. -### How does `yield` work? +More deatils in this [Stack Overflow answer](https://stackoverflow.com/a/4467012). -[answer on Stack Overflow](https://stackoverflow.com/a/1059501) +### How does `for / yield` work? + +In short it is sugar syntax for nested +`map`, `flatMap` & `withFilter` calls. + +For an in-depth explanation +see this [Stack Overflow answer](https://stackoverflow.com/a/1059501). ### What is the difference between view, stream and iterator? -[answer on Stack Overflow](https://stackoverflow.com/a/5159356) +[Answer on Stack Overflow](https://stackoverflow.com/a/5159356). ### Can I chain or nest implicit conversions? -[answer on Stack Overflow](https://stackoverflow.com/a/5332804) +Not really, but you can [make it work](https://stackoverflow.com/a/5332804) +_(although implicit conversions are, in general, discouraged)_. ### Where does Scala look for implicits? -[answer on Stack Overflow](https://stackoverflow.com/a/5598107) +See this [answer on Stack Overflow](https://stackoverflow.com/a/5598107). ### Why do primitive type parameters erase to `Object`? @@ -106,8 +113,8 @@ So for example, a `List[Int]` in Scala code will appear to Java as a appear as type parameters, but couldn't they appear as their boxed equivalents, such as `List[java.lang.Integer]`? -One would hope so, but doing it that way was tried and it proved -impossible. [This SO question](https://stackoverflow.com/questions/11167430/why-are-primitive-types-such-as-int-erased-to-object-in-scala) +One would hope so, but doing it that way was tried and it proved impossible. +[This SO question](https://stackoverflow.com/questions/11167430/why-are-primitive-types-such-as-int-erased-to-object-in-scala) sadly lacks a concise explanation, but it does link to past discussions. ### What's the difference between methods and functions? @@ -120,9 +127,9 @@ differ from a function value such as: val square: Int => Int = x => x * x -[complete answer on Stack Overflow](https://stackoverflow.com/a/2530007/4111404) +[Complete answer on Stack Overflow](https://stackoverflow.com/a/2530007/4111404). -[summary with practical differences](https://tpolecat.github.io/2014/06/09/methods-functions.html) +[Summary with practical differences](https://tpolecat.github.io/2014/06/09/methods-functions.html). ### What's the difference between types and classes? @@ -133,27 +140,29 @@ Classes are primarily a runtime concept and are platform-dependent. At runtime on the JVM, every value is either a primitive value or an instance of exactly one class. -Some type information exists only at compile time, for multiple -reasons, most notoriously [type -erasure](https://en.wikipedia.org/wiki/Type_erasure). +Some type information exists only at compile time, +for multiple reasons, most notoriously +[type erasure](https://en.wikipedia.org/wiki/Type_erasure). For an in-depth treatment of types vs. classes, see the blog post ["There are more types than classes"](https://typelevel.org/blog/2017/02/13/more-types-than-classes.html). ### How can a method in a superclass return a value of the “current” type? -Possible solutions include F-bounded polymorphism (familiar to Java programmers), -type members, and the typeclass pattern. - -[discussion of alternatives on Stack Overflow](https://stackoverflow.com/questions/59813323/advantages-of-f-bounded-polymorphism-over-typeclass-for-return-current-type-prob) +Possible solutions include F-bounded polymorphism +_(familiar to Java programmers)_, type members, +and the [typeclass pattern](http://tpolecat.github.io/2013/10/12/typeclass.html). -[blog post](http://tpolecat.github.io/2015/04/29/f-bounds.html) arguing against F-bounds and in favor of typeclasses. +This [blog post](http://tpolecat.github.io/2015/04/29/f-bounds.html) +argues against F-bounds and in favor of typeclasses. +Which is revisited with a discussion about the trade-offs of alternatives +in [this Stack Overflow post](https://stackoverflow.com/questions/59813323/advantages-of-f-bounded-polymorphism-over-typeclass-for-return-current-type-prob). ### What does `<:<` mean? It's a "type constraint", and it comes from the standard library, -not from the language itself. See [this blog -post](https://blog.bruchez.name/2015/11/generalized-type-constraints-in-scala.html). +not from the language itself. +See [this blog post](https://blog.bruchez.name/2015/11/generalized-type-constraints-in-scala.html). ### I dislike requiring callers to wrap optional arguments in `Some(...)`; is there a better way? @@ -161,5 +170,5 @@ Not really. See [this answer on Stack Overflow](https://stackoverflow.com/a/6525 ### Why is `implicit val` usually recommended over `implicit object`? -The latter has a singleton type, which is too specific. See [answer on Stack -Overflow](https://stackoverflow.com/a/65258340/4111404). +The latter has a singleton type, which is too specific. +See [answer on Stack Overflow](https://stackoverflow.com/a/65258340/4111404). From 71dc43b779a45cac45c39af3a82248d0890b27f5 Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Sat, 12 Dec 2020 13:32:42 -0800 Subject: [PATCH 2/3] small tweaks to Luis's edits --- _overviews/FAQ/index.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/_overviews/FAQ/index.md b/_overviews/FAQ/index.md index 541fcbafac..409889f115 100644 --- a/_overviews/FAQ/index.md +++ b/_overviews/FAQ/index.md @@ -81,14 +81,13 @@ See the [Scala 2.13 Collections Guide](https://docs.scala-lang.org/overviews/col ### What are context bounds (`[T : Foo]`)? -Basically is sugar syntax for an `implicit` argument of type `Foo[T]`. +It's syntactic sugar for an `implicit` parameter of type `Foo[T]`. -More deatils in this [Stack Overflow answer](https://stackoverflow.com/a/4467012). +More details in this [Stack Overflow answer](https://stackoverflow.com/a/4467012). ### How does `for / yield` work? -In short it is sugar syntax for nested -`map`, `flatMap` & `withFilter` calls. +It is syntactic sugar for nested `map`, `flatMap`, and `withFilter` calls. For an in-depth explanation see this [Stack Overflow answer](https://stackoverflow.com/a/1059501). @@ -99,8 +98,8 @@ see this [Stack Overflow answer](https://stackoverflow.com/a/1059501). ### Can I chain or nest implicit conversions? -Not really, but you can [make it work](https://stackoverflow.com/a/5332804) -_(although implicit conversions are, in general, discouraged)_. +Not really, but you can [make it work](https://stackoverflow.com/a/5332804). +But note that implicit conversions are, in general, discouraged. ### Where does Scala look for implicits? @@ -155,7 +154,7 @@ and the [typeclass pattern](http://tpolecat.github.io/2013/10/12/typeclass.html) This [blog post](http://tpolecat.github.io/2015/04/29/f-bounds.html) argues against F-bounds and in favor of typeclasses. -Which is revisited with a discussion about the trade-offs of alternatives +Another discussions of trade-offs and alternatives is in [this Stack Overflow post](https://stackoverflow.com/questions/59813323/advantages-of-f-bounded-polymorphism-over-typeclass-for-return-current-type-prob). ### What does `<:<` mean? From 712018e985c90774592da4b715c52bb34d7c068e Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Sat, 12 Dec 2020 19:24:43 -0800 Subject: [PATCH 3/3] FAQ: adjust wording in one place --- _overviews/FAQ/index.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/_overviews/FAQ/index.md b/_overviews/FAQ/index.md index 409889f115..4772f3c8ef 100644 --- a/_overviews/FAQ/index.md +++ b/_overviews/FAQ/index.md @@ -153,9 +153,8 @@ _(familiar to Java programmers)_, type members, and the [typeclass pattern](http://tpolecat.github.io/2013/10/12/typeclass.html). This [blog post](http://tpolecat.github.io/2015/04/29/f-bounds.html) -argues against F-bounds and in favor of typeclasses. -Another discussions of trade-offs and alternatives is -in [this Stack Overflow post](https://stackoverflow.com/questions/59813323/advantages-of-f-bounded-polymorphism-over-typeclass-for-return-current-type-prob). +argues against F-bounds and in favor of typeclasses; +see also [this Stack Overflow post](https://stackoverflow.com/questions/59813323/advantages-of-f-bounded-polymorphism-over-typeclass-for-return-current-type-prob) for some counterpoint. ### What does `<:<` mean?