Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
fmap(), "inverse" of Python map() function
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
vasudevram  
View profile  
 More options Oct 5 2012, 4:19 pm
Newsgroups: comp.lang.python
From: vasudevram <vasudev...@gmail.com>
Date: Fri, 5 Oct 2012 13:19:17 -0700 (PDT)
Local: Fri, Oct 5 2012 4:19 pm
Subject: fmap(), "inverse" of Python map() function
 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Kelly  
View profile  
 More options Oct 5 2012, 5:32 pm
Newsgroups: comp.lang.python
From: Ian Kelly <ian.g.ke...@gmail.com>
Date: Fri, 5 Oct 2012 15:31:35 -0600
Local: Fri, Oct 5 2012 5:31 pm
Subject: Re: fmap(), "inverse" of Python map() function

On Fri, Oct 5, 2012 at 2:19 PM, vasudevram <vasudev...@gmail.com> wrote:

> http://jugad2.blogspot.in/2012/10/fmap-inverse-of-python-map-function...

Your fmap is a special case of reduce.

def fmap(functions, argument):
    return reduce(lambda result, func: func(result), functions, argument)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Kelly  
View profile  
 More options Oct 5 2012, 5:44 pm
Newsgroups: comp.lang.python
From: Ian Kelly <ian.g.ke...@gmail.com>
Date: Fri, 5 Oct 2012 15:43:31 -0600
Local: Fri, Oct 5 2012 5:43 pm
Subject: Re: fmap(), "inverse" of Python map() function

On Fri, Oct 5, 2012 at 3:31 PM, Ian Kelly <ian.g.ke...@gmail.com> wrote:
> On Fri, Oct 5, 2012 at 2:19 PM, vasudevram <vasudev...@gmail.com> wrote:

>> http://jugad2.blogspot.in/2012/10/fmap-inverse-of-python-map-function...

> Your fmap is a special case of reduce.

> def fmap(functions, argument):
>     return reduce(lambda result, func: func(result), functions, argument)

In a more functional style, you could also use reduce to compose the
functions before applying them:

def compose(f, g):
    return lambda x: f(g(x))

def fmap(functions):
    return reduce(compose, reversed(functions))

# Allowing you to then do:
result = fmap(functions)(argument)

Cheers,
Ian


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Devin Jeanpierre  
View profile  
 More options Oct 5 2012, 6:53 pm
Newsgroups: comp.lang.python
From: Devin Jeanpierre <jeanpierr...@gmail.com>
Date: Fri, 5 Oct 2012 18:52:41 -0400
Local: Fri, Oct 5 2012 6:52 pm
Subject: Re: fmap(), "inverse" of Python map() function

On Fri, Oct 5, 2012 at 5:31 PM, Ian Kelly <ian.g.ke...@gmail.com> wrote:
> On Fri, Oct 5, 2012 at 2:19 PM, vasudevram <vasudev...@gmail.com> wrote:

>> http://jugad2.blogspot.in/2012/10/fmap-inverse-of-python-map-function...

> Your fmap is a special case of reduce.

So is map.

def map(f, seq):
    return reduce(
        lambda rseq, newpre:
            rseq.append(f(newpre)) or rseq,
        seq,
        [])

"X is a special case of reduce" is basically the same as saying "X can
be implemented using a for loop". If it's meant as a complaint, it's a
poor one.

-- Devin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Kelly  
View profile  
 More options Oct 5 2012, 7:24 pm
Newsgroups: comp.lang.python
From: Ian Kelly <ian.g.ke...@gmail.com>
Date: Fri, 5 Oct 2012 17:24:14 -0600
Local: Fri, Oct 5 2012 7:24 pm
Subject: Re: fmap(), "inverse" of Python map() function

On Fri, Oct 5, 2012 at 4:52 PM, Devin Jeanpierre <jeanpierr...@gmail.com> wrote:
> On Fri, Oct 5, 2012 at 5:31 PM, Ian Kelly <ian.g.ke...@gmail.com> wrote:
>> On Fri, Oct 5, 2012 at 2:19 PM, vasudevram <vasudev...@gmail.com> wrote:

>>> http://jugad2.blogspot.in/2012/10/fmap-inverse-of-python-map-function...

>> Your fmap is a special case of reduce.

> So is map.

I realize that.  My point is that the function *feels* more like a
variant of reduce than of map.

> If it's meant as a complaint, it's a poor one.

It's not.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Devin Jeanpierre  
View profile  
 More options Oct 5 2012, 7:31 pm
Newsgroups: comp.lang.python
From: Devin Jeanpierre <jeanpierr...@gmail.com>
Date: Fri, 5 Oct 2012 19:30:57 -0400
Local: Fri, Oct 5 2012 7:30 pm
Subject: Re: fmap(), "inverse" of Python map() function

On Fri, Oct 5, 2012 at 7:24 PM, Ian Kelly <ian.g.ke...@gmail.com> wrote:
> I realize that.  My point is that the function *feels* more like a
> variant of reduce than of map.

>> If it's meant as a complaint, it's a poor one.

> It's not.

Fair enough all around. Sorry for misunderstanding.

-- Devin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
vasudevram  
View profile  
 More options Oct 6 2012, 2:57 pm
Newsgroups: comp.lang.python
From: vasudevram <vasudev...@gmail.com>
Date: Sat, 6 Oct 2012 11:57:58 -0700 (PDT)
Local: Sat, Oct 6 2012 2:57 pm
Subject: Re: fmap(), "inverse" of Python map() function

Thanks to all who replied. Always good to learn something new.

- Vasudev


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
vasudevram  
View profile  
 More options Oct 6 2012, 2:58 pm
Newsgroups: comp.lang.python
From: vasudevram <vasudev...@gmail.com>
Date: Sat, 6 Oct 2012 11:57:58 -0700 (PDT)
Local: Sat, Oct 6 2012 2:57 pm
Subject: Re: fmap(), "inverse" of Python map() function

Thanks to all who replied. Always good to learn something new.

- Vasudev


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
vasudevram  
View profile  
 More options Oct 6 2012, 6:07 pm
Newsgroups: comp.lang.python
From: vasudevram <vasudev...@gmail.com>
Date: Sat, 6 Oct 2012 15:07:00 -0700 (PDT)
Subject: Re: fmap(), "inverse" of Python map() function

> Thanks to all who replied. Always good to learn something new.

P.S. A reader posted a good comment with Scala as well as Python code for a compose function (basically same functionality as fmap, or more - the compose once, run many times thing). It's the 4th comment on my blog post.

- Vasudev


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
vasudevram  
View profile  
 More options Oct 6 2012, 6:07 pm
Newsgroups: comp.lang.python
From: vasudevram <vasudev...@gmail.com>
Date: Sat, 6 Oct 2012 15:07:00 -0700 (PDT)
Subject: Re: fmap(), "inverse" of Python map() function

> Thanks to all who replied. Always good to learn something new.

P.S. A reader posted a good comment with Scala as well as Python code for a compose function (basically same functionality as fmap, or more - the compose once, run many times thing). It's the 4th comment on my blog post.

- Vasudev


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »