Skip to content

Commit 2132c10

Browse files
committed
Avoid some head and tail partial functions.
1 parent d47229b commit 2132c10

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Diff for: src/Text/TeXMath/Readers/MathML.hs

+10-10
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import Data.Monoid (First(..), getFirst)
5252
import Data.List (transpose)
5353
import Control.Applicative ((<|>))
5454
import qualified Data.Text as T
55-
import Control.Monad (filterM, guard)
55+
import Control.Monad (filterM, mzero)
5656
import Control.Monad.Reader (ReaderT, runReaderT, asks, local)
5757
import Data.Either (rights)
5858

@@ -449,14 +449,14 @@ underover e = do
449449
-- Other
450450

451451
semantics :: Element -> MML Exp
452-
semantics e = do
453-
guard (not $ null cs)
454-
first <- safeExpr (head cs)
455-
if isEmpty first
456-
then fromMaybe empty . getFirst . mconcat <$> mapM annotation (tail cs)
457-
else return first
458-
where
459-
cs = elChildren e
452+
semantics e =
453+
case elChildren e of
454+
[] -> mzero
455+
(c:cs) -> do
456+
first <- safeExpr c
457+
if isEmpty first
458+
then fromMaybe empty . getFirst . mconcat <$> mapM annotation cs
459+
else return first
460460

461461
annotation :: Element -> MML (First Exp)
462462
annotation e = do
@@ -509,7 +509,7 @@ tableRow a e = do
509509
align <- maybe a toAlignment <$> (findAttrQ "columnalign" e)
510510
case name e of
511511
"mtr" -> mapM (tableCell align) (elChildren e)
512-
"mlabeledtr" -> mapM (tableCell align) (tail $ elChildren e)
512+
"mlabeledtr" -> mapM (tableCell align) (drop 1 $ elChildren e)
513513
_ -> throwError $ "Invalid Element: Only expecting mtr elements " <> err e
514514

515515
tableCell :: Alignment -> Element -> MML (Alignment, [Exp])

0 commit comments

Comments
 (0)