dbuenzli / fmt

OCaml Format pretty-printer combinators
http://erratique.ch/software/fmt
ISC License
71 stars 26 forks source link

Add `Fmt.if'`. #57

Closed rizo closed 1 year ago

rizo commented 1 year ago

I was surprised this isn't present. This is similar to https://erratique.ch/software/bos/doc/Bos/Cmd/index.html#val-on

dbuenzli commented 1 year ago

I don't remember why but nowadays I rather moved to use if', see for example:

https://erratique.ch/software/b0/doc/B0_std/Cmd/index.html#val-if' https://erratique.ch/software/brr/doc/Brr/At/index.html#val-if' https://erratique.ch/software/webs/doc/Webs_html/At/index.html#val-if'

what do you think ?

rizo commented 1 year ago

No strong opinions, but my thoughts are:

Happy to rename this to Fmt.if'.

dbuenzli commented 1 year ago

I grepped a bit my code bases and even in the Cmd case (which often happens inside a Cmd.()) I definitively find if' clearer to read and, considering the following progression, more natural:

Fmt.(if cond then that_way else this_way)
Fmt.(if cond then that_way else nop)
Fmt.(if' cond that_way)

I rather keep on for labelling FRP event values.

rizo commented 1 year ago

That makes sense. Pushed Fmt.if'.

Would you consider adding Cmd.if' to Bos in that case and deprecating Cmd.on?

dbuenzli commented 1 year ago

Thanks your patch is in as 9db1a3c058973

Would you consider adding Cmd.if' to Bos in that case and deprecating Cmd.on?

https://github.com/dbuenzli/bos/commit/6320f302eb9487518491511292a11ee6f04bd6e9