Re: Re: Any should have map for readability
Carl Emmoth <[email protected]> Tue, 23 Aug 2016 13:28:17 +0200
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <CAE0Mqd+Q42VfS8x8_vxi2GUZptBNtnUrwr8AM9TW4qBgd+6oMw@mail.gmail.com> |
--047d7b3a890623c3f0053abb761a
Content-Type: text/plain; charset=UTF-8
Cool! Another
class Monad[T](val x : T) {
def >>=[S](f : T => S) : Monad[S] = {
new Monad(f(x))
}
override def toString = String.valueOf(x)
}
object Monad {
def apply[T](t : T) : Monad[T] = {
new Monad(t)
}
}
implicit def anyToMonad[T](x : T): Monad[T] = new Monad[T](x)
Den 5 aug. 2016 12:58 skrev "Jasper-M" <[email protected]>:
> 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 a topic in the
> Google Groups "scala-language" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/scala-language/OoI5jYiszYI/unsubscribe.
> To unsubscribe from this group and all its topics, 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.
--047d7b3a890623c3f0053abb761a
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr">Cool! Another <br><br></p>
<p dir=3D"ltr">class Monad[T](val x : T) {<br></p>
<p dir=3D"ltr">=C2=A0def >>=3D[S](f : T =3D> S) : Monad[S] =3D {</=
p>
<p dir=3D"ltr">=C2=A0=C2=A0=C2=A0new Monad(f(x))</p>
<p dir=3D"ltr">=C2=A0}<br></p>
<p dir=3D"ltr">=C2=A0override def toString =3D String.valueOf(x)</p>
<p dir=3D"ltr">}</p>
<p dir=3D"ltr">object Monad {<br></p>
<p dir=3D"ltr">=C2=A0def apply[T](t : T) : Monad[T] =3D {</p>
<p dir=3D"ltr">=C2=A0=C2=A0=C2=A0new Monad(t)</p>
<p dir=3D"ltr">=C2=A0}</p>
<p dir=3D"ltr">}<br></p>
<p dir=3D"ltr">implicit def anyToMonad[T](x : T): Monad[T] =3D new Monad[T]=
(x)</p>
<div class=3D"gmail_extra"><br><div class=3D"gmail_quote">Den 5 aug. 2016 1=
2:58 skrev "Jasper-M" <<a href=3D"mailto:[email protected]=
">[email protected]</a>>:<br type=3D"attribution"><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex"><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"courier new, monospace">}</font></div><div><font face=3D"courier n=
ew, monospace"><br></font></div><div><font face=3D"courier new, monospace">=
Http.serve(":8080", service) $ Await.ready $ println</font><br></=
div><br>Op vrijdag 5 augustus 2016 11:11:26 UTC+2 schreef Carl Emmoth:<bloc=
kquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-lef=
t:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Warning: Amateur sugges=
tion!<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"overflow-x:auto;overfl=
ow-y:hidden;font-family:Consolas,Menlo,"Deja Vu Sans Mono","=
Bitstream 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,73);background:rgb(253,253,253)"><span style=3D"color:rgb(0,68,97);fo=
nt-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,40,0)">.</span=
><span style=3D"color:rgb(0,0,0)">serve</span><span style=3D"color:rgb(88,4=
0,0)">(</span><span style=3D"color:rgb(78,154,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,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 a topic in the Goog=
le Groups "scala-language" group.<br>
To unsubscribe from this topic, visit <a href=3D"https://groups.google.com/=
d/topic/scala-language/OoI5jYiszYI/unsubscribe" target=3D"_blank">https://g=
roups.google.com/d/<wbr>topic/scala-language/<wbr>OoI5jYiszYI/unsubscribe</=
a>.<br>
To unsubscribe from this group and all its topics, send an email to <a href=
=3D"mailto:[email protected]" target=3D"_blank">s=
cala-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>
</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 />
--047d7b3a890623c3f0053abb761a--