polyvariadic: Creation and application of polyvariadic functions

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.


Creation and application of polyvariadic functions, see the docs for usage and examples

[Skip to ReadMe]


Change logChangeLog.md
Dependenciesbase (>=4.7 && <4.11), containers (>=0.1 && <0.6), semigroups (==0.18.*) [details]
Copyright(C) Francesco Gazzetta 2017
AuthorFrancesco Gazzetta
Home pagehttps://github.com/fgaz/polyvariadic
Source repositoryhead: git clone git://github.com/fgaz/polyvariadic.git
UploadedTue Dec 19 17:37:40 UTC 2017 by fgaz




Maintainers' corner

For package maintainers and hackage trustees

Readme for polyvariadic-

[back to package description]


Creation and application of polyvariadic functions

Build Status Hackage

For example, the classic printf:

{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
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))
>>> printf' "aaa%bbb%ccc%ddd" "TEST" 123 True