Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7404297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:14:10+00:00 2026-05-29T05:14:10+00:00

Python 3.2 documentation refers to Collin Winter’s functional module which contains function compose :

  • 0

Python 3.2 documentation refers to Collin Winter’s functional module which contains function compose:

The compose() function implements function composition. In other
words, it returns a wrapper around the outer and inner callables, such
that the return value from inner is fed directly to outer.

Unfortunately, this module hasn’t been updated since July 2006; I wonder if there’s any replacement available.

For now, I only need compose function. Is the following original functional.compose definition still good for Python 3?

def compose(func_1, func_2, unpack=False):
    """
    compose(func_1, func_2, unpack=False) -> function

    The function returned by compose is a composition of func_1 and func_2.
    That is, compose(func_1, func_2)(5) == func_1(func_2(5))
    """
    if not callable(func_1):
        raise TypeError("First argument to compose must be callable")
    if not callable(func_2):
        raise TypeError("Second argument to compose must be callable")

    if unpack:
        def composition(*args, **kwargs):
            return func_1(*func_2(*args, **kwargs))
    else:
        def composition(*args, **kwargs):
            return func_1(func_2(*args, **kwargs))
    return composition

This SO question is somewhat related; it asks whether Python should support special syntax for compose.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:14:11+00:00Added an answer on May 29, 2026 at 5:14 am

    Your implementation of compose is valid for python 3.2 as discussed in the comments above.
    Most of the functions of the library you gave have a python equivalent written in the documentation.

    Functions such as map and filter are already implemented in python and can also be simply expressed as list comprehensions. Python has an id function returning the identity of an object (as integer), but the id function of the library can be expressed as lambda x: x.

    Another modules you might find interesting are itertools and functools which has partial and reduce (which is similar to foldl but the argument order is not the same).

    Here is a simple implementations of a few of them that I didn’t find in the standard library:

    from functools import reduce
    
    def flip(f):
        if not callable(f):
            raise TypeError("Cannot filp a non-callable object")
        def result(*args, **kw):
            args = list(args)
            args.reverse()
            return f(*args, **kw)
        return result
    
    def ilast(i):
        return reduce(lambda _, x: x, i)
    
    def iscanl(f, v, seq):
        yield v
        for a in seq:
            v = f(v, a)
            yield v
    
    def scanl(*args, **kw):
        return list(iscanl(*args, **kw))
    
    def foldl(*args, **kw):
        return ilast(iscanl(*args, **kw))
    # Or using reduce
    #def foldl(f, v, seq):
    #    return reduce(f, seq, v)
    
    def iscanr_reverse(f, v, seq):
        return iscanl(flip(f), v, seq)
    
    def scanr(*args, **kw):
        result = list(iscanr_reverse(*args, **kw))
        result.reverse()
        return result
    
    def foldr(*args, **kw):
        return ilast(iscanr_reverse(*args, **kw))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't tell from the Python documentation whether the re.compile(x) function may throw an
The documentation of the Python readline module says Availability: Unix. However, it doesn't appear
I see the function SerializeAsString in the protobuf Python documentation , but like this
In python documentation it is wrote for built-in function complex([real[imag]]): ..or convert a string
There's a part of __import__ in Python documentation, which I don't understand: __import__(name[, globals[,
The documentation of sorl thumbnail still refers to the get_thumbnail function, but this doesn't
I have had the following problem which both Google and the Python documentation cannot
Python documentation to Popen states: Warning Use communicate() rather than .stdin.write, .stdout.read or .stderr.read
Using the Python Documentation I found the HTML parser but I have no idea
In the Python documentation it says: A thread can be flagged as a daemon

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.