[server] Add return value to tree modules
Now, tree modules can't just stop, they can Just stop. Sorry... But they can return values now, with a tiny bit of type class trickery.
This commit is contained in:
parent
220b5a3234
commit
2a2b148046
6 changed files with 55 additions and 39 deletions
|
|
@ -4,6 +4,7 @@ module Forest.Util
|
|||
( findPrev
|
||||
, findNext
|
||||
, whileM
|
||||
, runUntilJustM
|
||||
, withThread
|
||||
, sendPacket
|
||||
, closeWithErrorMessage
|
||||
|
|
@ -34,6 +35,14 @@ whileM f = do
|
|||
then whileM f
|
||||
else pure ()
|
||||
|
||||
-- | Run a monadic action until it returns @Just a@ for the first time.
|
||||
runUntilJustM :: Monad m => m (Maybe a) -> m a
|
||||
runUntilJustM f = do
|
||||
result <- f
|
||||
case result of
|
||||
Nothing -> runUntilJustM f
|
||||
Just a -> pure a
|
||||
|
||||
sendPacket :: ToJSON a => WS.Connection -> a -> IO ()
|
||||
sendPacket conn packet = WS.sendTextData conn $ encode packet
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue