function-composition

Function composition in Java

I'm trying to implement a lazy sequence (meaning that the next item is only calculated when you invoke the step function), and one of the methods it should have is "map" which receives a function that affects all the members. The most elegant way to do this is to use function composition, and assign the new function to the function varia...

Composing functions in Java?

I'm writing demo code for an API we've created and I keep running into the same problem where I'm repeating myself, over and over ad nauseum. I am painfully aware that Java is scheduled to have closures added but I don't have access to them now. Here is what is repeated all over the place that I'd like to just box into it's own little ...

Python function composition

I've tried to implement function composition with nice syntax and here is what I've got: from functools import partial class _compfunc(partial): def __lshift__(self, y): f = lambda *args, **kwargs: self.func(y(*args, **kwargs)) return _compfunc(f) def __rshift__(self, y): f = lambda *args, **kwargs: y(...

Is it a good idea to have a syntax sugar to function composition in Python?

Some time ago I looked over Haskell docs and found it's functional composition operator really nice. So I've implemented this tiny decorator: from functools import partial class _compfunc(partial): def __lshift__(self, y): f = lambda *args, **kwargs: self.func(y(*args, **kwargs)) return _compfunc(f) def __rshi...

Python list as *args?

I have two Python functions, both of which take variable arguments in their function definitions. To give a simple example: def func1(*args): for arg in args: print arg def func2(*args): return [2 * arg for arg in args] I'd like to compose them -- as in func1(func2(3, 4, 5)) -- but I don't want args in func1 to be ([6...

Haskell function composition (.) and function application ($) idioms: correct use.

I have been reading Real World Haskell and I am nearing the end but a matter of style has been niggling at me to do with the (.) and ($) operators. When you write a function that is a composition of other functions you write it like: f = g . h But when you apply something to the end of those functions I write it like this: k = a $ b...

Am I properly using function composition?

In an effort to understand the capabilities of functional programming I put together a few basic functions that you can compose together to build complex regular expressions. Now after some testing I have found this works but you can write some horrible code in any language that will work. Is this the kind of code you would find a profes...

Serialize Composed Func?

This works fine: Func<string, string> func1 = s => s + "func"; ViewState["function"] = func1; However, this does not: Func<string, string> func1 = s => s + "func"; Func<string, string> func2 = s => func1(s); ViewState["function"] = func2; It throws a runtime serialization exception: Type 'MyProjectName._Default...