Re: Re: Any should have map for readability
Vlad Patryshev <[email protected]> Tue, 23 Aug 2016 07:38:58 -0700
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <CAFhNTo_ssECHSwsQyiWZE9ybOAwrtUfDQQXgj+cs6X31q3qEfQ@mail.gmail.com> |
--001a113d126831a059053abe2199 Content-Type: text/plain; charset=UTF-8 This is cool. (Except that I would not be so optimistic and return total (pure) types from functions like serve or ready. Meaning, a monad makes more sense here, I think. Thanks, -Vlad On Fri, Aug 5, 2016 at 3:58 AM, Jasper-M <[email protected]> wrote: > 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. > -- 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. --001a113d126831a059053abe2199 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">This is cool.<div>(Except that I would not be so optimisti= c and return total (pure) types from functions like serve or ready. Meaning= , a monad makes more sense here, I think.</div></div><div class=3D"gmail_ex= tra"><br clear=3D"all"><div><div class=3D"gmail_signature" data-smartmail= =3D"gmail_signature">Thanks,<br>-Vlad</div></div> <br><div class=3D"gmail_quote">On Fri, Aug 5, 2016 at 3:58 AM, Jasper-M <sp= an dir=3D"ltr"><<a href=3D"mailto:[email protected]" target=3D"_blan= k">[email protected]</a>></span> wrote:<br><blockquote class=3D"gmai= l_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left= :1ex"><div dir=3D"ltr">Or write you own extension method?<div><br></div><di= v><div><font face=3D"courier new, monospace">implicit class Chained[T](val = t: T) extends AnyVal {</font></div><div><font face=3D"courier new, monospac= e">=C2=A0 def $[R](f: T=3D>R): R =3D f(t)</font></div><div><font face=3D= "courier new, monospace">}</font></div><div><font face=3D"courier new, mono= space"><br></font></div><div><font face=3D"courier new, monospace">Http.ser= ve(":8080", service) $ Await.ready $ println</font><br></div><br>= Op vrijdag 5 augustus 2016 11:11:26 UTC+2 schreef Carl Emmoth:<div><div cla= ss=3D"h5"><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0= .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Warning:= Amateur suggestion!<div><font size=3D"4">Example</font></div><div>So there= 's a lot of code examples in this form:</div><div><pre style=3D"overflo= w-x:auto;overflow-y:hidden;font-family:Consolas,Menlo,"Deja Vu Sans Mo= no","Bitstream Vera Sans Mono",monospace;font-size:0.9em;pad= ding:10px;line-height:1.3em;border-radius:5px;border:1px solid rgb(238,238,= 238);color:rgb(62,67,73);background:rgb(253,253,253)"><span style=3D"color:= rgb(0,68,97);font-weight:bold">val</span> <span style=3D"color:rgb(0,0,0)">= server</span> <span style=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,4= 0,0)">.</span><span style=3D"color:rgb(0,0,0)">serve</span><span style=3D"c= olor:rgb(88,40,0)">(</span><span style=3D"color:rgb(78,154,6)">":8080&= quot;</span><span style=3D"color:rgb(88,40,0)">,</span> <span style=3D"colo= r: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></div></div><div class=3D"= HOEnZb"><div class=3D"h5"> <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]" targ= et=3D"_blank">scala-language+unsubscribe@<wbr>googlegroups.com</a>.<br> For more options, visit <a href=3D"https://groups.google.com/d/optout" targ= et=3D"_blank">https://groups.google.com/d/<wbr>optout</a>.<br> </div></div></blockquote></div><br></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 /> --001a113d126831a059053abe2199--