From 233d7635c41c463db8deb7298ef91246663fbffc Mon Sep 17 00:00:00 2001 From: pingu Date: Thu, 19 Dec 2024 15:50:53 +0100 Subject: [PATCH] Welp, now it can fetch linsen again --- src/Model/Linsen.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Model/Linsen.hs b/src/Model/Linsen.hs index 726e3d7..e3f7d1a 100644 --- a/src/Model/Linsen.hs +++ b/src/Model/Linsen.hs @@ -16,6 +16,8 @@ import Control.Monad ( (>=>) import Control.Monad.Catch ( MonadThrow ) import Control.Monad.IO.Class ( MonadIO (liftIO) ) import Data.Aeson ( (.:) + , (.:?) + , (.!=) , withObject , Value ) import Data.Aeson.Types ( Parser @@ -23,6 +25,7 @@ import Data.Aeson.Types ( Parser import Data.Bifunctor ( first ) import qualified Data.ByteString.Lazy.Char8 as BL8 import Data.Char ( isSpace ) +import Data.Functor ( (<&>) ) import Data.List.Extra ( (!?) ) import Data.Text.Lazy ( Text , all @@ -108,10 +111,8 @@ parse day = >=> filterM (withObject "filter whitespace" $ (.: "children") >=> \case - [] -> fail "Empty list" - (v:_) -> pure v - >=> (.: "text") - >=> (pure . not . all isSpace)) + [] -> pure False + (v:_) -> (v .:? "text" .!= " ") <&> not . all isSpace) >=> (\v' -> (case v' !? 1 of Nothing -> fail "failed to index into food"