polyvariadic: Creation and application of polyvariadic functions

[ bsd3, data, library ] [ Propose Tags ] [ Report a vulnerability ]

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


[Skip to Readme]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.3.0.0, 0.3.0.1, 0.3.0.2, 0.3.0.3, 0.3.0.4 (info)
Change log ChangeLog.md
Dependencies base (>=4.7 && <4.17), containers (>=0.1 && <0.7), semigroups (>=0.18 && <0.19) [details]
Tested with ghc ==7.8.4, ghc ==7.10.3, ghc ==8.0.2, ghc ==8.2.2, ghc ==8.4.4, ghc ==8.6.5, ghc ==8.8.2, ghc ==8.10.2, ghc ==9.0.2, ghc ==9.2.2
License BSD-3-Clause
Copyright (C) Francesco Gazzetta 2017-2020
Author Francesco Gazzetta
Maintainer Francesco Gazzetta <fgaz@fgaz.me>
Revised Revision 2 made by fgaz at 2022-06-03T16:16:03Z
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
Reverse Dependencies 2 direct, 0 indirect [details]
Downloads 2899 total (11 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2020-02-04 [all 1 reports]

Readme for polyvariadic-0.3.0.4

[back to package description]

polyvariadic

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))
               done
>>> printf' "aaa%bbb%ccc%ddd" "TEST" 123 True
"aaa\"TEST\"bbb123cccTrueddd"