Copyright | (c) 2018-2020 Kowainik |
---|---|

License | MIT |

Maintainer | Kowainik <xrom.xkov@gmail.com> |

Stability | Experimental |

Portability | Portable |

Safe Haskell | Safe |

Language | Haskell2010 |

Functions to ease work with `newtypes`

.

*Since: 0.2.0*

## Synopsis

- un :: forall a n. Coercible a n => n -> a
- wrap :: forall n a. Coercible a n => a -> n
- under :: forall n a. Coercible a n => (n -> n) -> a -> a
- under2 :: forall n a. Coercible a n => (n -> n -> n) -> a -> a -> a
- underF2 :: forall n a. Coercible a (n a) => (n a -> n a -> n a) -> a -> a -> a
- (#.) :: Coercible b c => (b -> c) -> (a -> b) -> a -> c

# Documentation

un :: forall a n. Coercible a n => n -> a Source #

Unwraps value from `newtype`

.

`>>>`

`newtype Size = Size Int deriving Show`

`>>>`

5`un @Int (Size 5)`

`>>>`

False`un (Size 5) == length ['a', 'x', 'b']`

*Since: 0.2.0*

wrap :: forall n a. Coercible a n => a -> n Source #

Wraps value to `newtype`

. Behaves exactly as `un`

but has more meaningful
name in case you need to convert some value to `newtype`

.

`>>>`

`newtype Flag = Flag Bool deriving (Show, Eq)`

`>>>`

False`wrap False == Flag True`

*Since: 0.2.0*

under :: forall n a. Coercible a n => (n -> n) -> a -> a Source #

Applies function to the content of `newtype`

. This function is not supposed
to be used on `newtype`

s that are created with the help of smart constructors.

`>>>`

`newtype Foo = Foo Bool deriving Show`

`>>>`

Foo False`under not (Foo True)`

`>>>`

`newtype Bar = Bar String deriving Show`

`>>>`

Bar "aaaa"`under (filter (== 'a')) (Bar "abacaba")`

*Since: 0.2.0*

under2 :: forall n a. Coercible a n => (n -> n -> n) -> a -> a -> a Source #

Lift binary function for `newtype`

s to work over underlying `newtype`

representation.

`>>>`

7`under2 @(Sum Int) (<>) (3 :: Int) 4`

`>>>`

False`under2 @All (<>) True False`

*Since: 0.3.0*