when debug (putStrLn "Debugging")will output the string Debugging if the Boolean value debug is True, and otherwise do nothing.
>>> putStr "pi:" >> when False (print 3.14159) pi:
>>> whenM (pure False) $ putTextLn "No text :(" >>> whenM (pure True) $ putTextLn "Yes text :)" Yes text :) >>> whenM (Just True) (pure ()) Just () >>> whenM (Just False) (pure ()) Just () >>> whenM Nothing (pure ()) Nothing
>>> whenNotNull [] $ \(b :| _) -> print (not b) >>> whenNotNull [False,True] $ \(b :| _) -> print (not b) True
>>> whenLeftM "bar" (pure $ Left 42) (\a -> "success!" <$ print a) 42 "success!"
>>> whenLeftM "bar" (pure $ Right 42) (\a -> "success!" <$ print a) "bar"
>>> whenLeftM_ (pure $ Right 42) putTextLn >>> whenLeftM_ (pure $ Left "foo") putTextLn foo
>>> whenRightM "bar" (pure $ Left "foo") (\a -> "success!" <$ print a) "bar"
>>> whenRightM "bar" (pure $ Right 42) (\a -> "success!" <$ print a) 42 "success!"
>>> whenRightM_ (pure $ Left "foo") print >>> whenRightM_ (pure $ Right 42) print 42
>>> whenJust Nothing $ \b -> print (not b) >>> whenJust (Just True) $ \b -> print (not b) False
>>> whenJustM (pure Nothing) $ \b -> print (not b) >>> whenJustM (pure $ Just True) $ \b -> print (not b) False
>>> whenNothing Nothing [True, False] [True,False] >>> whenNothing (Just True) [True, False] [True]
>>> whenNothingM (pure $ Just True) $ True <$ putTextLn "Is Just!" True >>> whenNothingM (pure Nothing) $ False <$ putTextLn "Is Nothing!" Is Nothing! False
>>> whenNothingM_ (pure $ Just True) $ putTextLn "Is Just!" >>> whenNothingM_ (pure Nothing) $ putTextLn "Is Nothing!" Is Nothing!
>>> whenNothing_ Nothing $ putTextLn "Nothing!" Nothing! >>> whenNothing_ (Just True) $ putTextLn "Nothing!"