Any should have map for readability

104 views
Skip to first unread message

Carl Emmoth

unread,
Aug 5, 2016, 5:11:26 AM8/5/16
to scala-language
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)

Viktor Klang

unread,
Aug 5, 2016, 5:27:52 AM8/5/16
to scala-l...@googlegroups.com

Lift your Any into the Identity monad?

--
Cheers,


--
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 scala-language+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jasper-M

unread,
Aug 5, 2016, 6:58:39 AM8/5/16
to scala-language
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:

Carl Emmoth

unread,
Aug 23, 2016, 7:28:23 AM8/23/16
to scala-l...@googlegroups.com

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)


--
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 scala-language+unsubscribe@googlegroups.com.

Vlad Patryshev

unread,
Aug 23, 2016, 10:39:22 AM8/23/16
to scala-l...@googlegroups.com
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

--
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 scala-language+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages