-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Create and transform functions with variable arity. -- -- Please see the README on GitHub at -- https://github.com/lykahb/variadic-function#readme @package variadic-function @version 0.1.0.0 module Data.Function.Variadic -- | Toolkit for creating and transforming functions with a variable number -- of arguments. Its parameters are function, list of its arguments, its -- result, and argC that constraints all arguments of the -- function. class (ConstructFunction args r ~ f, DeconstructFunction f ~ '(args, r)) => Function f args r argC -- | Create a new function -- --
-- >>> printf :: Function Show f args String => f -- -- >>> printf = createFunction (Proxy :: Proxy Show) (\acc a -> acc <> show a) id "" -- -- >>> printf "hello" () :: String -- "hello()" --createFunction :: Function f args r argC => proxy argC -> (forall a. argC a => acc -> a -> acc) -> (acc -> r) -> acc -> f -- | Create a function with the same arguments as given one but may have a -- different result. transformFunction :: Function f args r argC => proxy argC -> (forall a. argC a => acc -> a -> acc) -> (acc -> r0 -> r) -> acc -> ConstructFunction args r0 -> f -- | Given the types of function arguments and its result, make a type of a -- function. type family ConstructFunction (args :: [Type]) (r :: Type) -- | Extract list of arguments and the result from the function. type family DeconstructFunction (f :: Type) :: ([Type], Type) -- | When the arguments are not constrained, use this as the argC parameter -- of Function. class EmptyConstraint a -- | Combine constraints. For example, Function f args x (Show & -- Num). class (f x, g x) => (&) f g (x :: k) instance forall k (f :: k -> GHC.Types.Constraint) (x :: k) (g :: k -> GHC.Types.Constraint). (f x, g x) => (Data.Function.Variadic.&) f g x instance forall k (a :: k). Data.Function.Variadic.EmptyConstraint a instance ('( '[], r) GHC.Types.~ Data.Function.Variadic.DeconstructFunction r) => Data.Function.Variadic.Function r '[] r argC instance (Data.Function.Variadic.Function f args r argC, argC a) => Data.Function.Variadic.Function (a -> f) (a : args) r argC module Data.Function.Variadic.Utils -- | Function composition for an arbitrary number of arguments. -- --
-- >>> (show `composeN` \a b c -> (a + b + c :: Int)) 1 2 3 -- "6" --composeN :: (Function f args b EmptyConstraint, Function g args a EmptyConstraint) => (a -> b) -> g -> f -- | Constant function for an arbitrary number of arguments. -- --
-- let const2 = constN :: x -> a -> b -> x ---- --
-- >>> zipWith3 (constN 1) [1..10] [1..5] ["a", "b", "c"] :: [Int] -- [1,1,1] --constN :: Function f args a EmptyConstraint => a -> f -- | Append multiple monoid values. It is similar to mconcat but -- takes the values as arguments rather than list elements. -- --
-- >>> mappendN [1, 2] [3] [4, 5] :: [Int] -- [1,2,3,4,5] --mappendN :: forall r f args. (Function f args r ((~) r), Monoid r) => f