summaryrefslogtreecommitdiff
path: root/compiler/utils
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/utils')
-rw-r--r--compiler/utils/Util.hs7
1 files changed, 7 insertions, 0 deletions
diff --git a/compiler/utils/Util.hs b/compiler/utils/Util.hs
index c484ba90ea..e8d20e3208 100644
--- a/compiler/utils/Util.hs
+++ b/compiler/utils/Util.hs
@@ -49,6 +49,8 @@ module Util (
changeLast,
+ whenNonEmpty,
+
-- * Tuples
fstOf3, sndOf3, thdOf3,
firstM, first3M, secondM,
@@ -137,6 +139,7 @@ import Data.Data
import Data.IORef ( IORef, newIORef, atomicModifyIORef' )
import System.IO.Unsafe ( unsafePerformIO )
import Data.List hiding (group)
+import Data.List.NonEmpty ( NonEmpty(..) )
import GHC.Exts
import GHC.Stack (HasCallStack)
@@ -610,6 +613,10 @@ changeLast [] _ = panic "changeLast"
changeLast [_] x = [x]
changeLast (x:xs) x' = x : changeLast xs x'
+whenNonEmpty :: Applicative m => [a] -> (NonEmpty a -> m ()) -> m ()
+whenNonEmpty [] _ = pure ()
+whenNonEmpty (x:xs) f = f (x :| xs)
+
{-
************************************************************************
* *