Questions tagged [map-function]

Higher-order function "map" transforms a collection by applying a given function to each element in it. USE [maps] for geography, [map] or [dictionary] for data types.

A map function is a higher-order function that applies a function to each element in a list, building a list of the results. Examples include map in Python, Scheme, Haskell and Scala, Stream.map in Java 8, array_map in PHP, and std::transform in C++.

A generalized map works with some general type of a collection, applying a function to each element in the collection and building the collection (of the same general type) of the results. An example is fmap in Haskell, etc.

For questions about geography, use the tag instead.

For questions about data types, use the tag instead, which is a synonym tag for .

829 questions
3
votes
2 answers

The state variable returned after using useState react hook shows .map is not a function

This code gives me error when I try to map the state variable returned after calling useEffect hook. On console, when I print the myAppointment it shows two values one is empty ([]) and other (Array[25]) I want to extract the petname values from…
Gazal Jain
  • 39
  • 1
  • 7
3
votes
2 answers

Why is mapcar only using one of the arguments returned from values-list?

I'm pretty new to Lisp and I have the following problem. I'm trying to swap the numbers around in multiple lists and produce a list of lists as the result, so that all the numbers that were the 1st number in each list will all be collected in a list…
BenKlee
  • 43
  • 3
3
votes
1 answer

How to apply a function to all elements of a tree?

data RoseTree a = RoseNode a [RoseTree a] deriving Show things :: RoseTree String things = RoseNode "thing" [ RoseNode "animal" [ RoseNode "cat" [], RoseNode "dog" [] ], RoseNode "metal" [ …
Jayyyyyy
  • 197
  • 1
  • 10
3
votes
3 answers

How to use mapM_ in this situation

I am trying to print different components of result of autocorrelation on different lines: import Data.Vector as V import Statistics.Autocorrelation import Data.Typeable sampleA = [1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4] main = do let res =…
rnso
  • 23,686
  • 25
  • 112
  • 234
3
votes
2 answers

Unexpected result with a membership test on a map object

I am a beginner in Python and am trying to solve the List Overlap problem on Practice Python. I have written some code for solving this but the code seems to have a mind of its own. It works sometimes and at other times it just returns a blank.…
Ani K
  • 33
  • 3
3
votes
1 answer

How to combine filter and mapping in Haskell

I'm making some exercises with haskell. My Task is to create a list of squares of even numbers without 0 from the list [0..10]. I already made it with the list comprehension in Haskell (Take a look in the code block below.) but now my task is to…
user10656336
3
votes
1 answer

How to rerender, if key stays the same, but other values change?

I'm writing a React app. I have a table of contacts: // ... pure functional component that gets the contacts via props return ( {fields.map(renderHeaderCell)} …
J. Hesters
  • 13,117
  • 31
  • 133
  • 249
3
votes
1 answer

Arrow function within jQuery map

I'm trying to use an arrow function within jQuery's map function. With the following titlesText is the correct length but each string is empty: let titles = $(panelBody).find('h4'); let titlesText = $(titles).map(title => $(title).text()); My ES6…
Ted Fitzpatrick
  • 910
  • 1
  • 8
  • 18
3
votes
2 answers

Tensorflow - Map-Function

I have a question concerning tf's map function. I encounter weird behavior with this function. If I do as stated in manual label_tensor # shape [150, 1] y = tf.map_fun(lambda x: x*x, label_tensor) # returns y as a tensor with label_tensor…
Hans T
  • 123
  • 1
  • 13
3
votes
2 answers

What does `int` parameter in `map` function of Python 3?

if __name__ == '__main__': n = int(input()) arr = map(int, input().split()) In the above code, map function taking two parameters, I got the understanding of the second parameter what it does but I am not getting 'int' parameter.
Prathamesh More
  • 1,470
  • 2
  • 18
  • 32
3
votes
2 answers

Using map with function that has multiple arguments

Is it possible to use map with a function that takes multiple arguments? I want to use map's second and third arguments repeatedly as the function's arguments. As in mapF x y z = map (f y z) [1, 2, 3] So it'll evaluate f with the same y and z…
3
votes
2 answers

how to create own map() function in python

I am trying to create the built-in map() function in python. Here is may attempt: def mapper(func, *sequences): if len(sequences) > 1: while True: list.append(func(sequences[0][0],sequences[0][0],)) return list return…
Makhele Sabata
  • 582
  • 6
  • 16
3
votes
2 answers

Is there an equivalent of Haskell's enumFromTo in Prolog?

I've just been starting out in Prolog and I was hoping to perform the following task: Make a predicate A(P,N,L) such that for all C which is nth element of L, P(N,C). Basically I want to perform a map on the range [0..N]. In Haskell, the language…
Wheat Wizard
  • 3,982
  • 14
  • 34
3
votes
2 answers

Is it possible to abort a map function on a Swift collection?

We have a case where we're being handed an object of type Array which we need to convert to an Array. If any of the items in the original array don't adhere to Codable, then we want the entire thing to abort and return nil. Or current…
Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286
3
votes
1 answer

Finding the three top tags

This is going to be a bit lengthy, but I'm looking for help as to how to tackle/think through this. I want to get into the habit of thinking critically with this problem, but I've hit a wall. So any tricks/tips/advice are appreciated. So I have an…