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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:18:02+00:00 2026-06-03T08:18:02+00:00

The code below from http://www.scalaclass.com/book/export/html/1 to do matrix dot product. I can’t understand the

  • 0

The code below from http://www.scalaclass.com/book/export/html/1 to do matrix dot product.

I can’t understand the syntax between the curly brackets.

  • Why are the curly brackets used, not the regular method parentheses?
  • Is t an anonymous method?
  • What is ._1 and ._2?

Thanks.

type Row    = List[Double]
type Matrix = List[Row]

def dotProd(v1:Row, v2:Row) = 
    v1.zip(v2).map{ t:(Double, Double) => t._1 * t._2 }.reduceLeft(_ + _)
  • 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-03T08:18:04+00:00Added an answer on June 3, 2026 at 8:18 am
    • Why are the curly brackets used, not the regular method parentheses?

    Some people prefer to use curly braces when the parameter is an anonymous function. For one thing, curly braces enable pattern matching anonymous functions, whereas parenthesis do not. In this particular example, there’s no need for curly braces.

    Here’s an example where curly braces are required (because of the case pattern matching):

    def dotProd(v1:Row, v2:Row) = 
        v1.zip(v2).map{ case (a, b) => a * b }.reduceLeft(_ + _)
    

    Note that the above function accomplishes the same thing as the one in the question, in a slightly different way.

    • Is t an anonymous method?

    No, it is a parameter. Just like v1 and v2 are parameters for dotProd, t is a parameter for the anonymous function being passed to map.

    • What is ._1 and ._2?

    Methods on t. The parameter t was defined as being a tuple (specifically, Tuple2[Double, Double], which can be written as (Double, Double)), and tuples let you extract each member of the tuple with methods like that: _1, _2, _3, etc.

    A Tuple2 only has _1 and _2, of course. Note that the first parameter is _1, not _0, because of influence from other functional languages.

    Anyway, the zip method will convert Row (List[Double]) into a List[(Double, Double)]. The method map takes a function that converts the elements of the list (which are (Double, Double) tuples) into something else.

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

Sidebar

Related Questions

I am using the code from http://www.imaputz.com/cssStuff/bigFourVersion.html . How do i put another big
Referring to the below link: http://www.javaworld.com/javaworld/jw-11-1998/jw-11-techniques.html?page=2 The composition approach to code reuse provides stronger
I have tried using the below code modified from http://www.html5rocks.com/tutorials/file/dndfiles/ to read in a
I got below code from http://msdn.microsoft.com/en-us/library/dd584174(office.11).aspx for adding custom property in webpart tool pane.
I have a java file Test.java (below) which uses Guava's HashMultiMap (downloaded from http://code.google.com/p/guava-libraries/
I am using AutoMapper to datareader using code as discussed below http://elegantcode.com/2009/10/16/mapping-from-idatareaderidatarecord-with-automapper/ I see
I would like to rewrite the URL of one of my pages from http://www.mydomain.com/some/application/page.html
From this tutorial http://www.brighthub.com/internet/web-development/articles/11010.aspx I found the code below. Is there a way to
I'm trying to apply the technique described in http://www.drdobbs.com/tools/227500449 With the sample code below,
I recently downloaded linux source from http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.34.1.tar.bz2 . I came across the below paragraph

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.