• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Map Function

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,
can anyone tell me when we should use map function?

Regards,
Gunjan
 
Rancher
Posts: 357
21
Mac OS X Monad Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In general 'map' is appropriate when you want to take a collection of items and produce a new collection with each item transformed in a particular way. The input and output collections will have the same length and each successive element of the output collection corresponds to the successive elements of the input collection.

If you want to produce a result that has a different shape to the input collection, you would use 'reduce' or 'fold' (different languages call them different things).

Does that help?
 
Gunjan Jadon
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sean Corfield wrote:In general 'map' is appropriate when you want to take a collection of items and produce a new collection with each item transformed in a particular way. The input and output collections will have the same length and each successive element of the output collection corresponds to the successive elements of the input collection.

If you want to produce a result that has a different shape to the input collection, you would use 'reduce' or 'fold' (different languages call them different things).

Does that help?



Thanks for reply Sean. Actually I have a code. I am not able to get why we are using map function in this code?

 
Marshal
Posts: 5003
319
IntelliJ IDE Python Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you're getting a little mixed up on this one.

What you have here is a Map data structure, sometimes called a Dictionary in other languages, rather than a map function as found in the functional programming paradigm.

An example of a map function might be to find the squares of all the numbers in a list. Take particular notice of line 4.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic