relude-0.5.0: Custom prelude from Kowainik

Copyright(c) 2016 Stephen Diehl
(c) 2016-2018 Serokell
(c) 2018-2019 Kowainik
LicenseMIT
MaintainerKowainik <xrom.xkov@gmail.com>
Safe HaskellSafe
LanguageHaskell2010

Relude.List.NonEmpty

Description

This module contains safe functions to work with list type in terms of NonEmpty.

Synopsis

Documentation

viaNonEmpty :: (NonEmpty a -> b) -> [a] -> Maybe b Source #

For safe work with lists using functinons for NonEmpty.

>>> viaNonEmpty head [1]
Just 1
>>> viaNonEmpty head []
Nothing

whenNotNull :: Applicative f => [a] -> (NonEmpty a -> f ()) -> f () Source #

Performs given action over NonEmpty list if given list is non empty.

>>> whenNotNull [] $ \(b :| _) -> print (not b)
>>> whenNotNull [False,True] $ \(b :| _) -> print (not b)
True

whenNotNullM :: Monad m => m [a] -> (NonEmpty a -> m ()) -> m () Source #

Monadic version of whenNotNull.