polyvariadic: Creation and application of polyvariadic functions

[ bsd3, data, library ] [ Propose Tags ]

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

[Skip to Readme]
Versions [faq],,,, (info)
Change log ChangeLog.md
Dependencies base (>=4.7 && <4.14), containers (>=0.1 && <0.7), semigroups (==0.18.*) [details]
License BSD-3-Clause
Copyright (C) Francesco Gazzetta 2017-2020
Author Francesco Gazzetta
Maintainer Francesco Gazzetta <fgaz@fgaz.me>
Category Data
Home page https://github.com/fgaz/polyvariadic
Source repo head: git clone git://github.com/fgaz/polyvariadic.git
Uploaded by fgaz at 2020-02-04T08:31:03Z
Distributions NixOS:
Downloads 2025 total (14 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2020-02-04 [all 1 reports]


[Index] [Quick Jump]


Maintainer's 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