Allow top-level "implicit class"es by folding them into containing package-object
Ryan Williams <[email protected]> Tue, 6 Dec 2016 19:26:24 -0800 (PST)
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_2193_981555661.1481081184694
Content-Type: multipart/alternative;
boundary="----=_Part_2194_46556132.1481081184694"
------=_Part_2194_46556132.1481081184694
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
The requirement that implicit classes be explicitly declared inside another=
=20
object gets in my way frequently and feels like it could be relaxed.
My typical library code looks like:
package foo.bar
object Baz {
implicit class Baz(=E2=80=A6) { =E2=80=A6 }
}
and corresponding calling code:
import foo.bar.Baz.Baz
One of the two Baz-layers is redundant.
Logically, i want my implicit classes to be considered to live inside their=
=20
nearest containing package object (in this case foo.bar), just like=20
non-implicit classes, but I can only declare a given package object once,=
=20
so to use it I have to put all classes in a package in the same file (in=20
the package object), which is also suboptimal.
LMK if I'm missing something? Thanks!
--=20
You received this message because you are subscribed to the Google Groups "=
scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to [email protected].
For more options, visit https://groups.google.com/d/optout.
------=_Part_2194_46556132.1481081184694
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>The requirement that implicit classes=C2=A0be explici=
tly declared inside another <font face=3D"courier new, monospace">object</f=
ont>=C2=A0gets in my way frequently and feels like it could be relaxed.</di=
v><div><br></div><div>My typical library code looks like:</div><div><br></d=
iv><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250)=
; border-color: rgb(187, 187, 187); border-style: solid; border-width: 1px;=
word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprett=
yprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">package</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> foo</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">bar<br><br></span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">object</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #606;" class=3D"styled-by-prettify">Baz</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">implicit</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">class</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Baz</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">(=E2=80=A6)</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">=E2=80=A6</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br></span></div></code></div><div><br></div><div>and corresponding calling=
code:</div><div><br></div><div class=3D"prettyprint" style=3D"background-c=
olor: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: s=
olid; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint=
"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"style=
d-by-prettify">import</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> foo</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">bar<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><sp=
an style=3D"color: #606;" class=3D"styled-by-prettify">Baz</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"colo=
r: #606;" class=3D"styled-by-prettify">Baz</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span></div></code></div><div><br></di=
v><div>One of the two <font face=3D"courier new, monospace">Baz</font>-laye=
rs is redundant.</div><div><br></div><div>Logically, i want my implicit cla=
sses to be considered to live inside their nearest containing <font face=3D=
"courier new, monospace">package object</font> (in this case <font face=3D"=
courier new, monospace">foo.bar</font>), just like non-implicit classes, bu=
t I can only declare a given <font face=3D"courier new, monospace">package =
object</font> once, so to use it I have to put all classes in a package in =
the same file (in the package object), which is also suboptimal.</div><div>=
<br></div><div>LMK if I'm missing something? Thanks!</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;scala-language" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">scal=
[email protected]</a>.<br />
For more options, visit <a href=3D"https://groups.google.com/d/optout">http=
s://groups.google.com/d/optout</a>.<br />
------=_Part_2194_46556132.1481081184694--
------=_Part_2193_981555661.1481081184694--