-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Creation and application of polyvariadic functions -- -- Creation and application of polyvariadic functions, see the docs for -- usage and examples @package polyvariadic @version 0.3.0.1 -- | Accumulators, primarily useful for Polyvariadic module Data.Accumulator -- | An 'Accumulator c i' supports accumulation of elements of type i in -- it. This is different from Semigroup or Monoid, where -- <> acts between two values with the same type. class Accumulator acc x accumulate :: Accumulator acc x => x -> acc -> acc -- | Accumulate a single value in a Monoid singleton :: (Accumulator acc x, Monoid acc) => x -> acc -- | Strictly accumulate multiple values from a Foldable, from left -- to right accumulateMany :: (Foldable f, Accumulator acc x) => f x -> acc -> acc -- | Lift a Semigroup into an Accumulator. This is a newtype because -- (<>) isn't always the ideal way of accumulating newtype AccumulatorSemigroup a AccumulatorSemigroup :: a -> AccumulatorSemigroup a [getAccumulatorSemigroup] :: AccumulatorSemigroup a -> a instance Data.Accumulator.Accumulator [a] a instance GHC.Classes.Ord a => Data.Accumulator.Accumulator (Data.Set.Base.Set a) a instance Data.Semigroup.Semigroup m => Data.Accumulator.Accumulator (Data.Accumulator.AccumulatorSemigroup m) (Data.Accumulator.AccumulatorSemigroup m) instance Data.Semigroup.Semigroup m => Data.Semigroup.Semigroup (Data.Accumulator.AccumulatorSemigroup m) -- | Create and apply functions with an arbitrary number of arguments. module Data.Function.Polyvariadic -- | Creation of functions with an arbitrary number of arguments. -- -- The arguments will be accumulated in the given Accumulator, -- which will then be passed as an argument to the function. -- --

Examples

-- -- Three integers to a list. Note that you have to add type annotations -- for nearly everything to avoid ambiguities >>> polyvariadic -- mempty (id :: [Int] -> [Int]) (1::Int) (2::Int) (3::Int) :: [Int] -- -- The classic printf function, which takes an arbitrary amount -- of arguments and inserts them in a string: -- --
--   {--}
--   {--}
--   {--}
--   import Data.Function.Polyvariadic
--   import Data.Accumulator
--   
--   magicChar = '%'
--   notMagicChar = (/= magicChar)
--   
--   data PrintfAccum = PrintfAccum { done :: String, todo :: String }
--   
--   instance Show x => Accumulator PrintfAccum x where
--     accumulate x (PrintfAccum done (_:todo)) = PrintfAccum
--                                                 (done ++ show x ++ takeWhile notMagicChar todo)
--                                                 (dropWhile notMagicChar todo)
--     accumulate _ acc = acc
--   
--   printf' str = polyvariadic
--                  (PrintfAccum (takeWhile notMagicChar str) (dropWhile notMagicChar str))
--                  done
--   
-- --
--   >>> printf' "aaa%bbb%ccc%ddd" "TEST" 123 True
--   "aaa\"TEST\"bbb123cccTrueddd"
--   
class Polyvariadic accumulator result x -- | Takes an accumulator acc, a function f, and an -- arbitrary number of additional arguments which will be accumulated in -- acc, which is finally passed to f. polyvariadic :: Polyvariadic accumulator result x => accumulator -> (accumulator -> result) -> x -- | Application of function with an arbitrary number of arguments to the -- elements of a list. -- -- Will raise an error if the list doesn't have enough elements -- --

Examples

-- --
--   >>> apply ((+) :: Int -> Int -> Int) ([1,2] :: [Int]) :: Int
--   3
--   
class Apply a b x apply' :: Apply a b x => x -> [a] -> b -- | Like apply' but with an arbitrary Foldable instead if a -- list apply :: (Apply a b x, Foldable t) => x -> t a -> b instance (Data.Accumulator.Accumulator c i, Data.Function.Polyvariadic.Polyvariadic c b x) => Data.Function.Polyvariadic.Polyvariadic c b (i -> x) instance Data.Function.Polyvariadic.Polyvariadic accumulator result result instance Data.Function.Polyvariadic.Apply a b x => Data.Function.Polyvariadic.Apply a b (a -> x) instance Data.Function.Polyvariadic.Apply a b b