<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>On May 9, 2015, at 11:33, Donald Stufft <<a href="mailto:donald@stufft.io">donald@stufft.io</a>> wrote:</div><div><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=us-ascii"><br class=""><div><blockquote type="cite" class=""><div class="">On May 9, 2015, at 2:30 PM, David Mertz <<a href="mailto:mertz@gnosis.cx" class="">mertz@gnosis.cx</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote">On Sat, May 9, 2015 at 1:16 PM, Steven D'Aprano <span dir="ltr" class=""><<a href="mailto:steve@pearwood.info" target="_blank" class="">steve@pearwood.info</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On Sat, May 09, 2015 at 11:38:38AM -0400, Ron Adam wrote:<br class="">
<br class="">
> How about an operator for partial?<br class="">
><br class="">
> root @ mean @ map $ square(xs)<br class=""></span></blockquote><div class=""><br class=""></div><div class="">I have trouble seeing the advantage of a special function composition operator when it is easy to write a general 'compose()' function that can produce such things easily enough.</div><div class=""><br class=""></div><div class="">E.g. in a white paper I just did for O'Reilly on _Functional Programming in Python_ I propose this little example implementation:</div><div class=""><br class=""></div><div class=""><div class="">def compose(*funcs):<br class=""></div><div class=""> "Return a new function s.t. compose(f,g,...)(x) == f(g(...(x)))"</div><div class=""> def inner(data, funcs=funcs):</div><div class=""> result = data</div><div class=""> for f in reversed(funcs):</div><div class=""> result = f(result)</div><div class=""> return result</div><div class=""> return inner</div></div><div class=""><br class=""></div><div class="">Which we might use as:</div><div class=""><br class=""></div><div class=""> RMS = compose(root, mean, square)</div><div class=""> result = RMS(my_array)</div></div></div></div></div></blockquote><br class=""></div><div><br class=""></div><div>Maybe functools.compose?</div></div></blockquote><div><br></div><div>But why?</div><div><br></div><div>This is trivial to write.</div><div><br></div><div>The nontrivial part is thinking through whether you want left or right compose, what you want to do about multiple arguments, etc. So, unless we can solve _that_ problem by showing that there is one and only one obvious answer, we don't gain anything by implementing one of the many trivial-to-implement possibilities in the stdlib.</div><div><br></div><div>Maybe as a recipe in the docs, it would be worth showing two different compose functions to demonstrate how easy it is to write whichever one you want (and how important it is to figure out which one you want).</div></body></html>