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 7563941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:47:32+00:00 2026-05-30T13:47:32+00:00

I’m having difficulty figuring out how to make the jump from a Scala high-order

  • 0

I’m having difficulty figuring out how to make the jump from a Scala high-order function definition to the example provided. It was provided in this slide show on slide 81.

Here’s the high-order function definition:

trait X[A] { def map[B](f: A => B): X[B] }

Here’s the examples provided:

(1 to 10) map { x => x * 2 } // evaluates to Vector(2, 4, ..., 20)
(1 to 10) map { _ * 2 }      // shorthand!

Huh?! There just HAS to be some steps in here I am missing. I get that the examples may be leveraging both the function definition AND some Scala niceties. I just don’t have enough experience reading Scala and making the connecting assumptions yet.

My background is as a Java OO. I am now learning Scala and functional programming. And this is not the first example like this I have not understood. It’s just the first one where I felt I had the courage to post knowing I would look ignorant.

I did try to research this. First, I went to the Scala “bible”, “Programming in Scala 2nd Edition”, and attempted to make sense of if from there (pages 165-9). Then, I did a search here on StackOverflow. And I found several links that talk around the area. But, nothing actually shows me, STEP-BY-STEP, the connection between a Scala high-order function definition and the provided examples in a way that maps to the particular instance in this slide.

Here’s what I found on StackOverflow:

  1. Scala: Workshop Advice
  2. More on generic Scala functions
  3. Scala: How to define "generic" function parameters?

I’m just now realizing that I skipped Google and came straight to StackOverflow. Hmmm. If you google and find just the right link, I would love seeing it. I’ve run out of time to sift through all the Google links which use terms like monkey-monad, blastomorphisms, etc. while leaving me even more confused and less likely to try and figure this out.

  • 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-30T13:47:33+00:00Added an answer on May 30, 2026 at 1:47 pm

    I think the following is just an example signature provided for the purpose of displaying some of Scala’s collection properties. In particular it does not show any implementation so you cannot really connect all the dots. Also it’s not actually consistent with the examples… So, may be this is confusing.

    trait X[A] { def map[B](f: A => B): X[B] }
    

    I would read that as: given a collection class X over elements of type A:

    • it has a map function that is parameterized on a type B
    • the map function takes a function f converting a single A to a single B
    • map returns a collection of the same type X over elements of type B.

    Then it jumps to the example to illustrates using:

    (1 to 10) map { x => x * 2 }
    

    So, connecting the dots:

    • The collection X is the type of (1 to 10), here a Range
    • f: A => B is x => x * 2 which is inferred as a function taking an Int and returning and Int.
    • Given the signature you would think that would return a Range over Int, but this actually returns an IndexedSeq.

    A better example may have been:

    List(1, 2, 3).map(i => i + "!") // a List[Int]
    // returns a List[String]: List("1!", "2!", "3!") 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
i got an object with contents of html markup in it, for example: string

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.