Any should have map for readability

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Any should have map for readability

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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Any should have map for readability

Viktor Klang

Lift your Any into the Identity monad?

--
Cheers,


On Aug 5, 2016 11:11 AM, "Carl Emmoth" <[hidden email]> wrote:
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 [hidden email].
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Any should have map for readability

Jasper-M
In reply to this post by Carl Emmoth
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Any should have map for readability

Carl Emmoth

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" <[hidden email]>:
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 [hidden email].
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Any should have map for readability

Vlad Patryshev
In reply to this post by Jasper-M
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 <[hidden email]> 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 [hidden email].
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.