Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #30846

Re: fmap(), "inverse" of Python map() function

References <727ec5d8-d292-4012-ba87-da77a1040c6a@googlegroups.com> <CALwzidmE5_LyKfEGqAGeN0Uv+g1fFo+ztjhZdr3b3vbRRnTvJA@mail.gmail.com>
From Devin Jeanpierre <jeanpierreda@gmail.com>
Date 2012-10-05 18:52 -0400
Subject Re: fmap(), "inverse" of Python map() function
Newsgroups comp.lang.python
Message-ID <mailman.1877.1349477604.27098.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, Oct 5, 2012 at 5:31 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On Fri, Oct 5, 2012 at 2:19 PM, vasudevram <vasudevram@gmail.com> wrote:
>>
>> http://jugad2.blogspot.in/2012/10/fmap-inverse-of-python-map-function.html
>
> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

fmap(), "inverse" of Python map() function vasudevram <vasudevram@gmail.com> - 2012-10-05 13:19 -0700
  Re: fmap(), "inverse" of Python map() function Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-05 15:31 -0600
  Re: fmap(), "inverse" of Python map() function Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-05 15:43 -0600
  Re: fmap(), "inverse" of Python map() function Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-10-05 18:52 -0400
  Re: fmap(), "inverse" of Python map() function Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-05 17:24 -0600
  Re: fmap(), "inverse" of Python map() function Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-10-05 19:30 -0400
    Re: fmap(), "inverse" of Python map() function vasudevram <vasudevram@gmail.com> - 2012-10-06 11:57 -0700
      Re: fmap(), "inverse" of Python map() function vasudevram <vasudevram@gmail.com> - 2012-10-06 15:07 -0700
      Re: fmap(), "inverse" of Python map() function vasudevram <vasudevram@gmail.com> - 2012-10-06 15:07 -0700
    Re: fmap(), "inverse" of Python map() function vasudevram <vasudevram@gmail.com> - 2012-10-06 11:57 -0700

csiph-web