use guards instead of if-else

This commit is contained in:
千住柱間 2025-08-28 01:50:53 +00:00
commit 99515f4520

View file

@ -10,7 +10,7 @@ import Control.Concurrent
import GI.Gtk
import GI.Gio hiding (Application)
import qualified GI.Gtk as GTK
import Control.Monad (when, void, mzero)
import Control.Monad (when, void, mzero, guard)
import Data.Foldable (for_)
import System.Directory (doesDirectoryExist, listDirectory)
import System.FilePath ((</>))
@ -19,13 +19,15 @@ import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
selectFolder :: FileDialog -> ApplicationWindow -> (Maybe String -> IO ()) -> IO ()
selectFolder fd w k = fileDialogSelectFolder fd (Just w) (Nothing :: Maybe Cancellable) $ Just $ \_ r -> do
mbPath <- runMaybeT $ do
f <- MaybeT $ handleDialogError (\_ _ -> return Nothing) (fileDialogSelectFolderFinish fd r)
p <- MaybeT $ fileGetPath f
e <- liftIO $ doesDirectoryExist p
if e then return p else mzero
k mbPath
selectFolder fd w k =
fileDialogSelectFolder fd (Just w) (Nothing :: Maybe Cancellable) $ Just $ \_ r -> do
mbPath <- runMaybeT $ do
f <- MaybeT $ handleDialogError (\_ _ -> pure Nothing)
(fileDialogSelectFolderFinish fd r)
p <- MaybeT $ fileGetPath f
guard =<< liftIO (doesDirectoryExist p)
pure p
k mbPath
main :: IO ()
main = do