Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7647605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:30:17+00:00 2026-05-31T10:30:17+00:00

Possible Duplicate: Why Option[T]? Reference types provide the special value null meaning "absence of

  • 0

Possible Duplicate:
Why Option[T]?

Reference types provide the special value null meaning "absence of a value". Value types have no such value, which is why C# introduced optional value types (along with special syntax for them).

Scala’s Option[T] has three different "null" values: null, None and Some(null). What exactly does this added complexity buy us in terms of safety and expressibility? When would I use which?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:30:18+00:00Added an answer on May 31, 2026 at 10:30 am

    Good Scala really only has one null value: None. Don’t use null (except for backward compatibility with existing Java code).

    There are many answers on SO regarding why Option[T] is useful. For example: see this.

    The short version:

    It makes the optional nature a signature explicit. The following clearly states that we expect that t could be “null”:

    def f(t: Option[T]) 
    

    You don’t have to null-check before operations: (i: Option[Int]) => i.map(_ + 1) works fine whether i is Some(5) or None, and preserves the Option wrapper to indicate that the input could have been None (and, thus, the output might be None as well).

    def f(i: Option[Int]) = i.map(_ + 1)
    f(Some(5)) // Some(6)
    f(None)    // None
    

    You can compose them easily with other Options or collections:

    val a: Option[Int] = Some(1)
    val b: Option[Int] = Some(6)
    val c: Option[Int] = Some(5)
    val d: Option[Int] = None
    for(x <- a; y <- b; z <- c) yield x + y + z // Some(12)
    for(x <- a; y <- d; z <- c) yield x + y + z // None
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Error when echo $_GET[“jsoncallback”] <select name=test> <option value=1>1</option> <option value=2>2</option> <option value=3>3</option>
Possible Duplicate: How do I show the changes which have been staged? Is there
Possible Duplicate: Better way of converting a Map[K, Option[V]] to a Map[K,V] I have
Possible Duplicate: How to parse JSON easily? I have this string: [{text: 'First Option',
Possible Duplicate: Why does Mac's $find not have the option -printf? Not sure what
Possible Duplicate: Passing a Int value to another class I have been trying to
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: LINQ to MySQL - what is the best option? I've been looking
Possible Duplicate: Child Scope & CS0136 C# Variable Scoping Though I have been using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.