---
title: "Discussion on \"Safeguarding Collections and Object References with Scala's Option\" | Hashnode"
description: "Discussion on \"Safeguarding Collections and Object References with Scala's Option\". We often use Option to handle collections safely:\nval collection = Map.empty[Int, Int]\n\n// unsafe way that will throw an exception if key is not present\nval value = collection(1)\n\n// safe way\nval valueOpt = collection.get(1) match {\n    case Some(val..."
url: "https://hashnode.com/posts/safeguarding-collections-and-object-references-with-scalas-option/64d58bb33197a7a87a3ec604"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Safeguarding Collections and Object References with Scala's Option](https://martianov.dev/safeguarding-collections-and-object-references-with-scalas-option?utm_source=hashnode&utm_medium=feed)

We often use Option to handle collections safely: val collection = Map.empty\[Int, Int\] // unsafe way that will throw an exception if key is not present val value = collection(1) // safe way val valueOpt = collection.get(1) match { case Some(val...

Aug 11, 2023 · 1 min read · martianov.dev  
Read the article

-   [#scala](https://hashnode.com/tag/scala)
-   [#software-engineering](https://hashnode.com/tag/software-engineering)
-   [#software-development](https://hashnode.com/tag/software-development)

## Written by

[Maksim Martianov](https://hashnode.com/@martianov)

@martianov · Seattle, WA

  
[View profile](https://hashnode.com/@martianov)

SWE at Snowflake. Ex-SWE Twitter/X, Route4me

Staff Software Engineer at Snowflake. Expert in scalable architecture, cloud infra, and security. Passionate problem-solver and mentor.

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
