Re: Any should have map for readability
Jasper-M <[email protected]> Fri, 5 Aug 2016 03:58:38 -0700 (PDT)
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_1531_931380700.1470394718945
Content-Type: multipart/alternative;
boundary="----=_Part_1532_1253226267.1470394718946"
------=_Part_1532_1253226267.1470394718946
Content-Type: text/plain; charset=UTF-8
Or write you own extension method?
implicit class Chained[T](val t: T) extends AnyVal {
def $[R](f: T=>R): R = f(t)
}
Http.serve(":8080", service) $ Await.ready $ println
Op vrijdag 5 augustus 2016 11:11:26 UTC+2 schreef Carl Emmoth:
>
> Warning: Amateur suggestion!
> Example
> So there's a lot of code examples in this form:
>
> val server = Http.serve(":8080", service)Await.ready(server)
>
>
> 1. Instancing
> 2. Calling method with instance
>
> It might look concrete but the instancing looks unnecessary.
> Suggestion
> Since we usually read from left to right, we would also like to read the
> code in chronological order like when using map
>
> Http.serve(":8080", service) map Await.ready
>
>
> But since Any doesn't have map, a suggested syntax would be
>
> Http.serve(":8080", service) (Await.ready)
>
> Similartiy with Collection
> This is similar to collections which have map. Here's examples with map
>
> 1 to 3 map println
>
> 1 to 3 map (_ + 10) map println
>
>
> Any without map could be like this then
>
> 10 (println)
>
> 10 (_ + 10) (println)
>
>
--
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 email to [email protected].
For more options, visit https://groups.google.com/d/optout.
------=_Part_1532_1253226267.1470394718946
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Or write you own extension method?<div><br></div><div><div=
><font face=3D"courier new, monospace">implicit class Chained[T](val t: T) =
extends AnyVal {</font></div><div><font face=3D"courier new, monospace">=C2=
=A0 def $[R](f: T=3D>R): R =3D f(t)</font></div><div><font face=3D"couri=
er new, monospace">}</font></div><div><font face=3D"courier new, monospace"=
><br></font></div><div><font face=3D"courier new, monospace">Http.serve(&qu=
ot;:8080", service) $ Await.ready $ println</font><br></div><br>Op vri=
jdag 5 augustus 2016 11:11:26 UTC+2 schreef Carl Emmoth:<blockquote class=
=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #cc=
c solid;padding-left: 1ex;"><div dir=3D"ltr">Warning: Amateur suggestion!<d=
iv><font size=3D"4">Example</font></div><div>So there's a lot of code e=
xamples in this form:</div><div><pre style=3D"overflow-x:auto;overflow-y:hi=
dden;font-family:Consolas,Menlo,"Deja Vu Sans Mono","Bitstre=
am Vera Sans Mono",monospace;font-size:0.9em;padding:10px;line-height:=
1.3em;border-radius:5px;border:1px solid rgb(238,238,238);color:rgb(62,67,7=
3);background:rgb(253,253,253)"><span style=3D"color:rgb(0,68,97);font-weig=
ht:bold">val</span> <span style=3D"color:rgb(0,0,0)">server</span> <span st=
yle=3D"color:rgb(0,68,97);font-weight:bold">=3D</span> <span style=3D"color=
:rgb(0,0,0)">Http</span><span style=3D"color:rgb(88,40,0)">.</span><span st=
yle=3D"color:rgb(0,0,0)">serve</span><span style=3D"color:rgb(88,40,0)">(</=
span><span style=3D"color:rgb(78,154,6)">":8080"</span><span styl=
e=3D"color:rgb(88,40,0)">,</span> <span style=3D"color:rgb(0,0,0)">service<=
/span><span style=3D"color:rgb(88,40,0)">)</span>
<span style=3D"color:rgb(0,0,0)">Await</span><span style=3D"color:rgb(88,40=
,0)">.</span><span style=3D"color:rgb(0,0,0)">ready</span><span style=3D"co=
lor:rgb(88,40,0)">(</span><span style=3D"color:rgb(0,0,0)">server</span><sp=
an style=3D"color:rgb(88,40,0)">)</span></pre></div><div><ol><li><span styl=
e=3D"line-height:normal">Instancing=C2=A0</span></li><li><span style=3D"lin=
e-height:normal">Calling method with instance</span></li></ol><div>It might=
look concrete but the instancing looks unnecessary.</div></div><div><font =
size=3D"4">Suggestion</font></div><div>Since we usually read from left to r=
ight, we would also like to read the code in chronological order like when =
using map</div><div><pre style=3D"padding:10px;border:1px solid rgb(238,238=
,238);overflow-x:auto;overflow-y:hidden;font-family:Consolas,Menlo,"De=
ja Vu Sans Mono","Bitstream Vera Sans Mono",monospace;font-s=
ize:0.9em;line-height:1.3em;border-radius:5px;color:rgb(62,67,73);backgroun=
d:rgb(253,253,253)"><span style=3D"color:rgb(0,0,0)">Http</span><span style=
=3D"color:rgb(88,40,0)">.</span><span style=3D"color:rgb(0,0,0)">serve</spa=
n><span style=3D"color:rgb(88,40,0)">(</span><span style=3D"color:rgb(78,15=
4,6)">":8080"</span><span style=3D"color:rgb(88,40,0)">,</span> <=
span style=3D"color:rgb(0,0,0)">service</span><span style=3D"color:rgb(88,4=
0,0)">) map Await.ready</span></pre></div><div><br></div><div>But since Any=
doesn't have map, a suggested syntax would be</div><div><pre style=3D"=
padding:10px;border:1px solid rgb(238,238,238);overflow-x:auto;overflow-y:h=
idden;font-family:Consolas,Menlo,"Deja Vu Sans Mono","Bitstr=
eam Vera Sans Mono",monospace;font-size:0.9em;line-height:1.3em;border=
-radius:5px;color:rgb(62,67,73);background:rgb(253,253,253)"><span style=3D=
"color:rgb(0,0,0)">Http</span><span style=3D"color:rgb(88,40,0)">.</span><s=
pan style=3D"color:rgb(0,0,0)">serve</span><span style=3D"color:rgb(88,40,0=
)">(</span><span style=3D"color:rgb(78,154,6)">":8080"</span><spa=
n style=3D"color:rgb(88,40,0)">,</span> <span style=3D"color:rgb(0,0,0)">se=
rvice</span><span style=3D"color:rgb(88,40,0)">) (Await.ready)</span></pre>=
</div><div><font size=3D"4">Similartiy with Collection</font></div><div>Thi=
s is similar to collections which have map. Here's examples with map</d=
iv><div><pre style=3D"padding:10px;border:1px solid rgb(238,238,238);overfl=
ow-x:auto;overflow-y:hidden;font-family:Consolas,Menlo,"Deja Vu Sans M=
ono","Bitstream Vera Sans Mono",monospace;font-size:0.9em;li=
ne-height:1.3em;border-radius:5px;background:rgb(253,253,253)"><font color=
=3D"#000000">1 to 3 map println</font></pre><pre style=3D"padding:10px;bord=
er:1px solid rgb(238,238,238);overflow-x:auto;overflow-y:hidden;border-radi=
us:5px;background:rgb(253,253,253)"><font color=3D"#000000"><font face=3D"C=
onsolas, Menlo, Deja Vu Sans Mono, Bitstream Vera Sans Mono, monospace"><sp=
an style=3D"font-size:11.7px;line-height:15.21px">1 to 3 map (_ + 10) map p=
rintln</span><span style=3D"font-size:0.9em;line-height:1.3em"><br></span><=
/font></font></pre></div><div><br></div><div>Any without map could be like =
this then</div><div><pre style=3D"padding:10px;border:1px solid rgb(238,238=
,238);overflow-x:auto;overflow-y:hidden;font-family:Consolas,Menlo,"De=
ja Vu Sans Mono","Bitstream Vera Sans Mono",monospace;font-s=
ize:0.9em;line-height:1.3em;border-radius:5px;background:rgb(253,253,253)">=
<font color=3D"#000000">10 (println)</font></pre><pre style=3D"padding:10px=
;border:1px solid rgb(238,238,238);overflow-x:auto;overflow-y:hidden;font-f=
amily:Consolas,Menlo,"Deja Vu Sans Mono","Bitstream Vera San=
s Mono",monospace;font-size:0.9em;line-height:1.3em;border-radius:5px;=
background:rgb(253,253,253)"><font color=3D"#000000">10 (_ + 10) (println)<=
/font></pre></div></div></blockquote></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_1532_1253226267.1470394718946--
------=_Part_1531_931380700.1470394718945--