Is there a function that applies list of functions to a value?

2013-08-28 Thread AdamKal
Hi, 

>From time to time I have to apply a series of functions to a value in such a 
>way:

func4(func3(func2(func1(myval

I was wondering if there is a function in standard library that would take a 
list of functions and a initial value and do the above like this:

func_im_looking_for([func1, func2, func3, func4], myval)

I looked in itertools but nothing seamed to do the job. This seams like 
something vary obvious that was needed many times elsewhere so maybe you could 
help me?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a function that applies list of functions to a value?

2013-08-28 Thread AdamKal
Thanks! 

I guess this is as simple as it gets then. I was just looking for the "one 
obvious way to do it".

W dniu środa, 28 sierpnia 2013 15:11:34 UTC+2 użytkownik Tim Chase napisał:
> On 2013-08-28 05:52, AdamKal wrote:
> 
> > From time to time I have to apply a series of functions to a value
> 
> > in such a way:
> 
> > 
> 
> > func4(func3(func2(func1(myval
> 
> > 
> 
> > I was wondering if there is a function in standard library that
> 
> > would take a list of functions and a initial value and do the above
> 
> > like this:
> 
> > 
> 
> > func_im_looking_for([func1, func2, func3, func4], myval)
> 
> 
> 
> At least in Py2.x you can use reduce:
> 
> 
> 
>   reduce(lambda value, fn: fn(value), [list_of_functions], myval)
> 
> 
> 
> I believe it was moved into functools.reduce() in Py3.x meaning you
> 
> might want to do something like
> 
> 
> 
>   try:
> 
> reduce # see if it's already in __builtins__
> 
>   except NameError: # running Py3...
> 
> from functools import reduce
> 
> 
> 
> or
> 
> 
> 
>   try:
> 
> from functools import reduce
> 
>   except ImportError:
> 
> pass  # it should already be in __builtins__ for pre-2.6
> 
> 
> 
> at the top to make sure it's in your global namespace.
> 
> 
> 
> -tkc

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a function that applies list of functions to a value?

2013-08-28 Thread AdamKal
W dniu środa, 28 sierpnia 2013 15:43:39 UTC+2 użytkownik Tim Chase napisał:
 
> When 3 replies from 3 people all arrive within minutes, each
> suggesting reduce(), I'd figure it's the "one obvious way to do 
> it" :-)

I guess it's at least a good hint ;)


Thanks to all! :)


-- 
http://mail.python.org/mailman/listinfo/python-list


CRUD library

2013-09-30 Thread AdamKal
Hi, 

Do you know any library or framework that unifies CRUD somehow. 
Maybe I'll describe my problem:

I have a application that uses many external services and processes them 
together. This are things like web services and DB and so on. In the REST era 
we usually operate on object and collections of objects (like in django's ORM) 
but have different source behind them. My idea was that there might be 
somewhere a unified abstraction layer that would require from programmers to 
write the CRUD methods and handle object creation and management (maybe even 
relations?) by itself. 
I've started to work on my own library for that but I wouldn't like to do 
something that someone has done already. 
Do you know any such library/framework?
Do you think that it makes any sense at all?

regards, 
Adam
-- 
https://mail.python.org/mailman/listinfo/python-list