AJChapman / formatting

Format strings type-safely with combinators
BSD 3-Clause "New" or "Revised" License
164 stars 39 forks source link

How to modify formatter's input? #26

Closed neongreen closed 7 years ago

neongreen commented 8 years ago

Just for the sake of example, say I want to create a formatter that would print first 8 characters of a string:

first8 :: Format r (String -> r)
first8 = string ??? take 8

How would I go about it? I feel that the answer is obvious, but I can't figure it out.

chrisdone commented 7 years ago
> format (fitLeft 5) "hel"
"hel"
neongreen commented 7 years ago

I know about fitLeft. I guess I should've explicitly clarified that “first 8 characters” was just an example and the actual use cases for “modify formatter's input” that I encounter don't have standard formatters for them.

Specifically, what I'm looking for is a function of this type:

(???) :: Format r (b -> r) -> (a -> b) -> Format r (a -> r)
chrisdone commented 7 years ago

Pushed to Hackage mapf.

neongreen commented 7 years ago

Wow. Thanks!