app package:tuple-sop

Applies a monomorphic function to the first element of an n-ary tuple that matches the type of the argument of the function.
>>> app not ('d',True)
('d',False)
Sometimes it is necessary to specify the result type, such that the function becomes monomorphic >>> app (+1) (True,5) :: (Bool,Integer) (True,6) One may also use appPoly, which doesn't require specifying the result type. However it can only apply functions to the first element of an n-ary tuple.
Applies a function to the first element of an n-ary tuple
>>> app1 (+1) (5,6,7)
(6,6,7)
Apply an n-ary function to an n-ary tuple. The function takes an argument for each component of the tuple in left-to-right order.
>>> appF (\a b c -> if a then b else c) (False,1,2)
2
Applies a function to the element at index n in an n-ary tuple.
>>> appN not (Proxy 2) (False,True,False)
(False,True,True)
appN also works for polymorphic functions
>>> appN show (5,'c',False) (Proxy :: Proxy 2)
(5,'c',"False")
Applies a polymorphic function to the first element of an n-ary tuple. Since the function is polymorphic in its argument it can always be applied to the first element of a tuple.
>>> appPoly show (5,False)
("5",False)
Appends two n-ary tuple into one larger tuple
>>> appendT (5,'c') ('d',False)
(5,'c','d',False)
Applies a polymorphic function to each element in an n-ary tuple. Requires all elements in the tuple to be of the same type.
>>> mapPolyT (+1) (5,6,7,8)
(6,7,8,9)
>>> mapPolyT (+1) (5,6,7,False)
No instance for (Num Bool) arising from the literal `5'