From a45394a21c65860e30782278562b0a8e1a8b0190 Mon Sep 17 00:00:00 2001 From: Joachim Fasting Date: Wed, 5 Mar 2008 18:20:02 +0000 Subject: [PATCH] [gitconv @ N.M.Commands.plChangesPosId: reimplement with error checking] Uses PatternGuards because not using them was seriously clunky. --- Network/MPD/Commands.hs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Network/MPD/Commands.hs b/Network/MPD/Commands.hs index 3d0b2b6..66eb4e1 100644 --- a/Network/MPD/Commands.hs +++ b/Network/MPD/Commands.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE PatternGuards #-} {- libmpd for Haskell, an MPD client library. Copyright (C) 2005-2008 Ben Sinclair @@ -22,7 +23,7 @@ -- License : LGPL -- Maintainer : bsinclai@turing.une.edu.au -- Stability : alpha --- Portability : Haskell 98 +-- Portability : unportable (uses PatternGuards) -- -- Interface to the user commands supported by MPD. @@ -399,9 +400,12 @@ plChanges version = -- | Like 'plChanges' but only returns positions and ids. plChangesPosId :: Integer -> MPD [(PLIndex, PLIndex)] plChangesPosId plver = - liftM (map takePosid . splitGroups . toAssoc) (getResponse cmd) - where cmd = "plchangesposid " ++ show plver - takePosid xs = (Pos $ takeNum "cpos" xs, ID $ takeNum "Id" xs) + getResponse ("plchangesposid " ++ show plver) >>= + mapM f . splitGroups . toAssoc + where f xs | [("cpos", x), ("Id", y)] <- xs + , Just (x', y') <- pair parseNum (x, y) + = return (Pos x', ID y') + | otherwise = throwError . Unexpected $ show xs -- | Search for songs in the current playlist with strict matching. playlistFind :: Query -> MPD [Song] -- 2.11.4.GIT