Skip to content

Commit

Permalink
Prepare changelog for the 0.4.0 release [skip ci] (#119)
Browse files Browse the repository at this point in the history
* Prepare changelog for the 0.4.0 release [skip ci]

* Improve docs and do some pretty things
  • Loading branch information
chshersh authored and vrom911 committed Nov 6, 2018
1 parent 47a3d01 commit 988bbdd
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 38 deletions.
38 changes: 23 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
# Change log

0.4.0
Unreleased
====

0.4.0 — Nov 6, 2018
=====

* [#70](https://github.com/kowainik/relude/issues/70):
Reexport `Contravariant` for GHC >= 8.6.1
* [#81](https://github.com/kowainik/relude/issues/81):
Add `asumMap` to `Foldable` functions.
Reexport `Contravariant` for GHC >= 8.6.1.
* [#103](https://github.com/kowainik/relude/pull/104):
Drop `utf8-string` dependency and improve performance of conversion functions.
* [#98](https://github.com/kowainik/relude/issues/98):
Reexport `Bifoldable` related stuff from `base`.
* [#99](https://github.com/kowainik/relude/issues/99):
Reexport `Bitraversable` related stuff from `base`.
* [#100](https://github.com/kowainik/relude/issues/100):
Add `Relude.Extra.Validation` with `Validation`data type.
* [#89](https://github.com/kowainik/relude/issues/81):
Add `Relude.Extra.Type` module containing a `typeName` function.
* [#92](https://github.com/kowainik/relude/issues/92)
Add `Relude.Extra.Tuple` module, containing
`dupe`, `mapToFst`, `mapToSnd`, and `mapBoth` functions.
* Remove `openFile` and `hClose`.
* [#98](https://github.com/kowainik/relude/issues/98):
Reexport `Bifoldable` related stuff from `base`.
* [#99](https://github.com/kowainik/relude/issues/99):
Reexport `Bitraversable` related stuff from `base`.
* [#97](https://github.com/kowainik/relude/issues/97):
Add `(&&^)` and `(||^)` operators.
* [#100](https://github.com/kowainik/relude/issues/100):
Add `Validation` data type to Extra modules.
* [#103](https://github.com/kowainik/relude/pull/104):
Drop utf8-string dependency.
* [#109](https://github.com/kowainik/relude/issues/109):
Use Dhall v3.0.0 for hlint file generation.
* [#81](https://github.com/kowainik/relude/issues/81):
Add `asumMap` to `Foldable` functions.
* [#80](https://github.com/kowainik/relude/issues/80):
Add hlint rules for `whenLeft`, `whenLeftM`, `whenRight` and `whenRightM`.
* [#79](https://github.com/kowainik/relude/issues/79):
Add HLint rules for `One` typeclass.
* Remove `openFile` and `hClose`.
* [#83](https://github.com/kowainik/relude/pull/83):
Make documentation for `nub` functions prettier.
* [#109](https://github.com/kowainik/relude/issues/109):
Use Dhall v3.0.0 for hlint file generation.

0.3.0
=====
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ Finally, we can move to part describing the new cool features we bring with `rel

* `Foldable1` typeclass that contains generalized interface for folding
non-empty structures like `NonEmpty`.
* `Validation` data type as an alternative to `Either` when you want to combine
all errors.

Explore `Extra` modules: [`Relude.Extra`](src/Relude/Extra/)

Expand Down
2 changes: 2 additions & 0 deletions src/Relude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ every module in your package by modifying your "Prelude" file:
'CallStack'.
* __"Relude.Extra.Enum"__: extra utilities for types that implement 'Bounded'
and 'Enum' constraints.
* __"Relude.Extra.Foldable1"__: 'Foldable1' typeclass like 'Foldable' but for
non-empty structures.
* __"Relude.Extra.Group"__: grouping functions, polymorphic on return @Map@ type.
* __"Relude.Extra.Map"__: typeclass for @Map@-like data structures.
* __"Relude.Extra.Newtype"__: generic functions that automatically work for any
Expand Down
4 changes: 2 additions & 2 deletions src/Relude/Extra/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Data.Typeable (Typeable, typeRep)

{- | Gets a string representation of a type.
Note: This must be used with -XTypeApplications
__NOTE:__ This must be used with __TypeApplications__ language extension.
>>> typeName @()
"()"
Expand All @@ -42,4 +42,4 @@ typeName = show (typeRep @a)
#else
typeName = show (typeRep (Proxy @a))
#endif
{-# INLINE typeName #-}
{-# INLINE typeName #-}
31 changes: 10 additions & 21 deletions src/Relude/Extra/Validation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ instance Functor (Validation e) where
fmap :: (a -> b) -> Validation e a -> Validation e b
fmap _ (Failure e) = Failure e
fmap f (Success a) = Success (f a)
{-# INLINE fmap #-}

(<$) :: a -> Validation e b -> Validation e a
x <$ Success _ = Success x
_ <$ Failure e = Failure e

{-# INLINE fmap #-}
{-# INLINE (<$) #-}

{- | __Examples__
Expand Down Expand Up @@ -67,14 +66,14 @@ Failure ["Not correct"]
instance Semigroup e => Applicative (Validation e) where
pure :: a -> Validation e a
pure = Success
{-# INLINE pure #-}

#if MIN_VERSION_base(4,10,0)
liftA2 :: (a -> b -> c) -> Validation e a -> Validation e b -> Validation e c
liftA2 _ (Failure el) (Failure er) = Failure (el <> er)
liftA2 _ (Failure e) (Success _) = Failure e
liftA2 _ (Success _) (Failure e) = Failure e
liftA2 f (Success a) (Success b) = Success (f a b)

{-# INLINE liftA2 #-}
#endif

Expand All @@ -84,95 +83,87 @@ instance Semigroup e => Applicative (Validation e) where
Success _ -> e
Success _ <*> Failure e = Failure e
Success f <*> Success a = Success (f a)
{-# INLINE (<*>) #-}

(*>) :: Validation e a -> Validation e b -> Validation e b
Failure el *> Failure er = Failure (el <> er)
Failure e *> Success _ = Failure e
Success _ *> Failure e = Failure e
Success _ *> Success b = Success b
{-# INLINE (*>) #-}

(<*) :: Validation e a -> Validation e b -> Validation e a
Failure el <* Failure er = Failure (el <> er)
Failure e <* Success _ = Failure e
Success _ <* Failure e = Failure e
Success a <* Success _ = Success a

{-# INLINE pure #-}
{-# INLINE (<*>) #-}
{-# INLINE (*>) #-}
{-# INLINE (<*) #-}

instance (Semigroup e, Monoid e) => Alternative (Validation e) where
empty :: Validation e a
empty = Failure mempty
{-# INLINE empty #-}

(<|>) :: Validation e a -> Validation e a -> Validation e a
s@Success{} <|> _ = s
_ <|> s@Success{} = s
Failure e <|> Failure e' = Failure (e <> e')

{-# INLINE empty #-}
{-# INLINE (<|>) #-}

instance Foldable (Validation e) where
fold :: Monoid m => Validation e m -> m
fold (Success a) = a
fold (Failure _) = mempty
{-# INLINE fold #-}

foldMap :: Monoid m => (a -> m) -> Validation e a -> m
foldMap _ (Failure _) = mempty
foldMap f (Success a) = f a
{-# INLINE foldMap #-}

foldr :: (a -> b -> b) -> b -> Validation e a -> b
foldr f x (Success a) = f a x
foldr _ x (Failure _) = x

{-# INLINE fold #-}
{-# INLINE foldMap #-}
{-# INLINE foldr #-}

instance Traversable (Validation e) where
traverse :: Applicative f => (a -> f b) -> Validation e a -> f (Validation e b)
traverse f (Success a) = Success <$> f a
traverse _ (Failure e) = pure (Failure e)
{-# INLINE traverse #-}

sequenceA :: Applicative f => Validation e (f a) -> f (Validation e a)
sequenceA = traverse id

{-# INLINE traverse #-}
{-# INLINE sequenceA #-}

instance Bifunctor Validation where
bimap :: (e -> d) -> (a -> b) -> Validation e a -> Validation d b
bimap f _ (Failure e) = Failure (f e)
bimap _ g (Success a) = Success (g a)
{-# INLINE bimap #-}

first :: (e -> d) -> Validation e a -> Validation d a
first f (Failure e) = Failure (f e)
first _ (Success a) = Success a
{-# INLINE first #-}

second :: (a -> b) -> Validation e a -> Validation e b
second _ (Failure e) = Failure e
second g (Success a) = Success (g a)

{-# INLINE bimap #-}
{-# INLINE first #-}
{-# INLINE second #-}

#if MIN_VERSION_base(4,10,0)
instance Bifoldable Validation where
bifoldMap :: Monoid m => (e -> m) -> (a -> m) -> Validation e a -> m
bifoldMap f _ (Failure e) = f e
bifoldMap _ g (Success a) = g a

{-# INLINE bifoldMap #-}

instance Bitraversable Validation where
bitraverse :: Applicative f
=> (e -> f d) -> (a -> f b) -> Validation e a -> f (Validation d b)
bitraverse f _ (Failure e) = Failure <$> f e
bitraverse _ g (Success a) = Success <$> g a

{-# INLINE bitraverse #-}
#endif

Expand All @@ -181,13 +172,11 @@ validationToEither :: Validation e a -> Either e a
validationToEither = \case
Failure e -> Left e
Success a -> Right a

{-# INLINE validationToEither #-}

-- | Transform an 'Either' into a 'Validation'.
eitherToValidation :: Either e a -> Validation e a
eitherToValidation = \case
Left e -> Failure e
Right a -> Success a

{-# INLINE eitherToValidation #-}

0 comments on commit 988bbdd

Please sign in to comment.