packages feed

papa-0.7.0: src/Papa/Base/Data/Functor.hs

{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wall #-}

-- | Functors, with 'map' generalised to any 'Functor'.
module Papa.Base.Data.Functor (
  module P,
  map,
) where

import Data.Functor as P (
  Functor (fmap, (<$)),
  void,
  ($>),
  (<$>),
  (<&>),
 )

-- $setup
-- >>> :set -XNoImplicitPrelude
-- >>> import Papa
-- >>> import Hedgehog
-- >>> import Hedgehog.Function (fn, apply)
-- >>> import qualified Hedgehog.Gen as Gen
-- >>> import qualified Hedgehog.Range as Range
-- >>> let genInts = Gen.list (Range.linear 0 20) (Gen.int (Range.linear (-100) 100))
-- >>> let genF = fn (Gen.int (Range.linear (-100) 100))

-- | 'fmap', under the name of "Prelude"'s @map@.
--
-- ==== __Examples__
--
-- >>> map (+ 1) [1, 2, 3 :: Int]
-- [2,3,4]
--
-- >>> map (+ 1) (Just (1 :: Int))
-- Just 2
--
-- >>> check $ withTests 100 $ property $ do xs <- forAll genInts; map id xs === xs
-- ...passed 100 tests.
-- True
--
-- >>> check $ withTests 100 $ property $ do xs <- forAll genInts; f <- forAll genF; g <- forAll genF; map (apply f . apply g) xs === map (apply f) (map (apply g) xs)
-- ...passed 100 tests.
-- True
--
-- @since 0.1.0
map :: (Functor f) => (a -> b) -> f a -> f b
map =
  fmap
{-# INLINE map #-}