Implement tree functions
This commit is contained in:
parent
54ec7afa59
commit
3255bfd2ec
3 changed files with 140 additions and 28 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue