# Scala map and filter methods

map(func) and filter(func) Both are first class methods. First class methods take function as input parameter or output as function.

Functional programming: Programming focusing on a function is used as input parameter of another function or methods or as output of another function or method

### map(func) method:

```
sc.parallelize(Seq(1,2,3,4,5)).map(x=>x+1).collect
/*
res0: Array[Int] = Array(2, 3, 4, 5, 6)
*/
```

### filter(func)

```
sc.parallelize(Seq(1,2,3,4,5)).filter(x=>x%2==0)
     .collect
/*
res2: Array[Int] = Array(2, 4)
*/
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://george-jen.gitbook.io/data-science-and-apache-spark/scala-map-and-filter-methods.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
