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

  • Home
  • SEARCH
  • 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 9204371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:41:50+00:00 2026-06-17T23:41:50+00:00

While trying to play with Options in scala I have come across this peculiar

  • 0

While trying to play with Options in scala I have come across this peculiar problem.

I started off with creating a List[Option[Int]] as follows:

scala> List(Some(1),Some(2),None,Some(3))
res0: List[Option[Int]] = List(Some(1), Some(2), None, Some(3))

Then I tried to map an addition to 1 over the entries of the list in res0 as follows:

scala> res0 map (_ + 1)

This gave me the error:

<console>:9: error: type mismatch;
 found   : Int(1)
 required: String
              res0 map (_ + 1)
                            ^

Then I tried flatMapping an addition over the entries as follows:

scala> res0 flatMap (_ + 1)

This gave me the same error:

<console>:9: error: type mismatch;
 found   : Int(1)
 required: String
              res0 flatMap (_ + 1)
                                ^

But something like res0.flatMap(r => r) works just fine with a result of:

res9: List[Int] = List(1, 2, 3)

Can anybody tell me why adding the entry to 1 would fail for both map and flatMap?

  • 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-06-17T23:41:51+00:00Added an answer on June 17, 2026 at 11:41 pm

    The first two things you tried failed because you are trying to add an Option to an Int, and that’s not possible.

    The weird error message happens because Scala assumes, since Option doesn’t have a + method, that you are trying String concatenation, but you’d have to either add an Option to a String, or a String to an Option, and you are doing neither, hence the error message.

    In the last case, you are not trying to add anything, you are simply returning Option as is, hence no error message.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While trying to learn Play Framework I ran across the following problem: How do
While trying to play video using media player, I am getting this error: Unable
I have been trying to play with SublimeText2 for some time now. While it
I have been trying to get this trigger created using Play 2.0.3. It runs
Trying to get an animation to play backwards while a button is held down,
While trying to troubleshoot a problem I'm having with a project, I noticed that
While trying to write an answer for another SO question something really peculiar happened.
I'm getting a strange error code while trying to play video. I get error
While I was trying to play with Pagination Support in Repeater, PagedDataSource rescued me.
I'm getting a key not found error message while trying to start my Play

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.