Implement tree functions

This commit is contained in:
Joscha 2020-02-09 11:29:19 +00:00
parent 54ec7afa59
commit 3255bfd2ec
3 changed files with 140 additions and 28 deletions

View file

@ -1,7 +1,9 @@
{-# LANGUAGE OverloadedStrings #-}
module Forest.Util
( withThread
( findPrev
, findNext
, withThread
, sendPacket
, receivePacket
, closeWithErrorMessage
@ -9,9 +11,16 @@ module Forest.Util
import Control.Concurrent.Async
import Data.Aeson
import Data.List
import qualified Data.Text as T
import qualified Network.WebSockets as WS
findPrev :: (a -> Bool) -> [a] -> Maybe a
findPrev f as = fst <$> find (f . snd) (zip as $ tail as)
findNext :: (a -> Bool) -> [a] -> Maybe a
findNext f as = snd <$> find (f . fst) (zip as $ tail as)
withThread :: IO () -> IO () -> IO ()
withThread thread main = withAsync thread $ const main