Skip to content

add unwrapF and unF #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Data/Newtype.purs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Data.Newtype where

import Data.Functor (class Functor)
import Data.Monoid.Additive (Additive(..))
import Data.Monoid.Conj (Conj(..))
import Data.Monoid.Disj (Disj(..))
Expand Down Expand Up @@ -56,6 +57,15 @@ instance newtypeLast :: Newtype (Last a) a
un :: forall t a. Newtype t a => (a -> t) -> t -> a
un _ = unwrap

-- | Cheap version of `map unwrap`.
unwrapF :: forall f t a. Functor f => Newtype t a => f t -> f a
unwrapF = coerce

-- | Given a constructor for a `Newtype`, this returns the appropriate `unwrapF`
-- | function.
unF :: forall f t a. Functor f => Newtype t a => (a -> t) -> f t -> f a
unF _ = unwrapF

-- | This combinator is for when you have a higher order function that you want
-- | to use in the context of some newtype - `foldMap` being a common example:
-- |
Expand Down