« Return to Thread: something like Clojure's "doto"?

Re: something like Clojure's "doto"?

by David Hall-15 :: Rate this Message:

Reply to Author | View in Thread

scala> def doto[A](a: A)(todos: (A=>Any)*) = todos.foldLeft(a){
(a,todo) => todo(a); a }
doto: [A](A)((A) => Any*)A

scala> doto(new java.util.HashMap[String,Int])(_.put("a",1),_.put("b",2))
res0: java.util.HashMap[String,Int] = {b=2, a=1}


On Wed, Jul 8, 2009 at 3:03 PM, Raoul Duke<raould@...> wrote:
> hi,
>
> is there / how might one implement something like
> http://clojure.org/java_interop#toc15 to get (even more) succinctness
> in Scala?
>
> many thanks.
> (i am experimenting with writing it on my own but am so far kinda lost.)
>

 « Return to Thread: something like Clojure's "doto"?