Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fgaz/polyvariadic
Create and apply polyvariadic functions
https://github.com/fgaz/polyvariadic
function haskell polyvariadic varargs
Last synced: 10 days ago
JSON representation
Create and apply polyvariadic functions
- Host: GitHub
- URL: https://github.com/fgaz/polyvariadic
- Owner: fgaz
- License: bsd-3-clause
- Created: 2017-04-08T13:13:02.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-06-03T16:11:32.000Z (over 2 years ago)
- Last Synced: 2024-10-11T22:44:09.338Z (26 days ago)
- Topics: function, haskell, polyvariadic, varargs
- Language: Haskell
- Homepage: https://hackage.haskell.org/package/polyvariadic
- Size: 27.3 KB
- Stars: 12
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
- License: LICENSE
Awesome Lists containing this project
README
# polyvariadic
**Creation and application of polyvariadic functions**
[![builds.sr.ht status](https://builds.sr.ht/~fgaz/polyvariadic/commits.svg)](https://builds.sr.ht/~fgaz/polyvariadic/commits?)
[![Hackage](https://img.shields.io/hackage/v/polyvariadic.svg)](https://hackage.haskell.org/package/polyvariadic)For example, the classic printf:
```haskell
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
import Data.Function.Polyvariadic
import Data.AccumulatormagicChar = '%'
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 = accprintf' str = polyvariadic
(PrintfAccum (takeWhile notMagicChar str) (dropWhile notMagicChar str))
done
``````haskell
>>> printf' "aaa%bbb%ccc%ddd" "TEST" 123 True
"aaa\"TEST\"bbb123cccTrueddd"
```