util 0.1.0.0 → 0.1.1.0
raw patch · 2 files changed
+33/−1 lines, 2 filesdep ~base
Dependency ranges changed: base
Files
- Util.hs +28/−0
- util.cabal +5/−1
Util.hs view
@@ -5,8 +5,14 @@ import Control.Monad import Data.Bool import Data.Function (flip)+import Data.Functor.Classes import Data.Maybe+import Data.Semigroup+import Data.Monoid+import Numeric.Natural +import Prelude (Enum (..), Bounded, Eq, Ord, Read, Show, Foldable, Traversable (..))+ infixr 3 &=& (&=&) :: Applicative p => (a -> p b) -> (a -> p c) -> a -> p (b, c) f &=& g = (liftA2 ∘ liftA2) (,) f g@@ -35,6 +41,9 @@ whileJust :: (Alternative f, Monad m) => m (Maybe a) -> (a -> m b) -> m (f b) whileJust mmx f = mmx >>= maybe (pure empty) (f >=> (<$> whileJust mmx f) ∘ (<|>) ∘ pure) +untilJust :: Monad m => m (Maybe a) -> m a+untilJust mmx = mmx >>= maybe (untilJust mmx) pure+ list :: b -> (a -> [a] -> b) -> [a] -> b list y _ [] = y list _ f (x:xs) = f x xs@@ -62,3 +71,22 @@ þrd3 :: (a, b, c) -> c þrd3 (_,_,z) = z++replicate :: Alternative f => Natural -> a -> f a+replicate 0 _ = empty+replicate n a = pure a <|> replicate (pred n) a++replicateA :: (Applicative p, Alternative f) => Natural -> p a -> p (f a)+replicateA 0 _ = pure empty+replicateA n a = (<|>) . pure <$> a <*> replicateA (pred n) a++mtimesA :: (Applicative p, Semigroup a, Monoid a) => Natural -> p a -> p a+mtimesA n = unAp . stimes n . Ap++newtype Ap p a = Ap { unAp :: p a }+ deriving (Functor, Applicative, Monad, Alternative, MonadPlus, Foldable, Traversable,+ Eq1, Ord1, Read1, Show1, Eq, Ord, Read, Show, Bounded, Enum)+instance (Applicative p, Semigroup a) => Semigroup (Ap p a) where (<>) = liftA2 (<>)+instance (Applicative p, Semigroup a, Monoid a) => Monoid (Ap p a) where+ mempty = pure mempty+ mappend = (<>)
util.cabal view
@@ -1,5 +1,5 @@ name: util-version: 0.1.0.0+version: 0.1.1.0 synopsis: Utilities -- description: license: BSD3@@ -19,4 +19,8 @@ -- hs-source-dirs: default-language: Haskell2010 default-extensions: NoImplicitPrelude+ , GeneralizedNewtypeDeriving+ , DeriveFunctor+ , DeriveFoldable+ , DeriveTraversable ghc-options: -Wall