<commit_before>## Map ##

Mangler en slide om Literals

---

```scala
class Map[A, +B] {
  ..
  def isEmpty: Boolean
  def nonEmpty: Boolean

  def size: Int

  def mkString: String
  def mkString(sep: String): String
  def mkString(start: String, sep: String, end: String): String
  ..
}
```
<aside class="notes">
    mye likt som List
</aside>

---

```scala
class Map[A, +B] {
  ..
  def filter(p: ((A, B)) ⇒ Boolean): Map[A, B]
  def filterKeys(p: (A) ⇒ Boolean): Map[A, B]

  def map[B](f: (A) ⇒ B): Map[B]
  def mapValues[C](f: (B) ⇒ C): Map[A, C]

  def partition(p: ((A, B)) ⇒ Boolean): (Map[A, B], Map[A, B])

  def withDefaultValue[B1 >: B](d: B1): Map[A, B1]

  def orElse[A1 <: A, B1 >: B](that: PartialFunction[A1, B1]): PartialFunction[A1, B1]
  ..
}
```

---

# Oppgaver #
collections Map*
<commit_msg>Literals og oppgave-slide for Map<commit_after>## Map ##

Literals
```scala
Map(1 -> 2, 2 -> 3)
Map((1, 2), (2, 3))
List((1, 2), (2, 3)).toMap

Map(1 -> 2, 2 -> 3) withDefaultValue 42
```

---

```scala
Map(1 -> 1) + (2 -> 2)     == Map(1 -> 1, 2 -> 2)
Map(1 -> 1, 2 -> 2) - 1    == Map(2 -> 2)
Map(1 -> 1) ++ Map(2 -> 2) == Map(1 -> 1, 2 -> 2)
```

---

```scala
class Map[A, +B] {
  ..
  def isEmpty: Boolean
  def nonEmpty: Boolean

  def size: Int

  def mkString: String
  def mkString(sep: String): String
  def mkString(start: String, sep: String, end: String): String
  ..
}
```
<aside class="notes">
    mye likt som List
</aside>

---

```scala
class Map[A, +B] {
  ..
  def filter(p: ((A, B)) ⇒ Boolean): Map[A, B]
  def filterKeys(p: (A) ⇒ Boolean): Map[A, B]

  def map[B](f: (A) ⇒ B): Map[B]
  def mapValues[C](f: (B) ⇒ C): Map[A, C]

  def partition(p: ((A, B)) ⇒ Boolean): (Map[A, B], Map[A, B])

  def withDefaultValue[B1 >: B](d: B1): Map[A, B1]

  def orElse[A1 <: A, B1 >: B](that: PartialFunction[A1, B1]): PartialFunction[A1, B1]
  ..
}
```

---

# Oppgaver #
scalakurs.collections.MapOppgaverTest

```scala
sbt:
> ~ test-only scalakurs.collections.MapOppgaverTest
```
{'fraction_non_alphanumeric': 0.22371699053313404, 'fraction_numerical': 0.029397110114598904, 'mean_word_length': 3.0979591836734692, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3594479', 'n_tokens_mistral': 939, 'n_tokens_neox': 876, 'n_words': 250}