This page is no longer maintained — Please continue to the home page at

Re: Stateful server without mutable state

No replies
Rüdiger Klaehn
Joined: 2009-06-02,
User offline. Last seen 42 years 45 weeks ago.

2011/10/29 √iktor Ҡlang :> I think Runar
solved dat sh!t recently by encoding it using trampolining.>
You mean this
? I think that is a bit over my head. All that to work around
limitations of the JVM regarding tail calls...
Anyway, I also managed to get it working by using Iterator.iterate.
It's extremely ugly though. I was hoping for something more elegant.

def hideState3(initial:State, respond: ((Req, State)) => (Res,
State)) : (Stream[Req] => Stream[Res]) = {
reqs => {
val dummyRes = null.asInstanceOf[Res]
Iterator.iterate((initial,reqs,dummyRes))({ x =>
val (state, reqs, _) = x
reqs match {
case req #:: tail =>
val (res, newState) = respond((req, state))
(newState, tail, res)
case _ =>
(state, reqs, dummyRes)

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland