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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:32:19+00:00 2026-06-01T01:32:19+00:00

I have some financial data gathered at a List[(Int, Double)], like this: val snp

  • 0

I have some financial data gathered at a List[(Int, Double)], like this:

val snp = List((2001, -13.0), (2002, -23.4))

With this, I wrote a formula that would transform the list, through map, into another list (to demonstrate investment grade life insurance), where losses below 0 are converted to 0, and gains above 15 are converted to 15, like this:

case class EiulLimits(lower:Double, upper:Double)
def eiul(xs: Seq[(Int, Double)], limits:EiulLimits): Seq[(Int, Double)] = {
    xs.map(item => (item._1, 
                    if (item._2 < limits.lower) limits.lower 
                    else if (item._2 > limits.upper) limits.upper 
                         else item._2
}

Is there anyway to extract the tuple’s values inside this, so I don’t have to use the clunky _1 and _2 notation?

  • 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-01T01:32:20+00:00Added an answer on June 1, 2026 at 1:32 am
    List((1,2),(3,4)).map { case (a,b) => ... }
    

    The case keyword invokes the pattern matching/unapply logic.

    Note the use of curly braces instead of parens after map


    And a slower but shorter quick rewrite of your code:

    case class EiulLimits(lower: Double, upper: Double) { 
      def apply(x: Double) = List(x, lower, upper).sorted.apply(1)
    }
    
    def eiul(xs: Seq[(Int, Double)], limits: EiulLimits) = {
      xs.map { case (a,b) => (a, limits(b)) } 
    }
    

    Usage:

    scala> eiul(List((1, 1.), (3, 3.), (4, 4.), (9, 9.)), EiulLimits(3., 7.))
    res7: Seq[(Int, Double)] = List((1,3.0), (3,3.0), (4,4.0), (7,7.0), (9,7.0))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have to build some financial data report, and for making the calculation, there
I've got some financial data to store and manipulate. Let's say I have 2
I have some perl code that looks something like this: my @array = map
I have some financial values stored as text in a mysql db. the significance
We have some COBOL programs in our financial applications which need to interact with
I need to extract financial price data from a binary file. This price data
I have a (C#) genetic program that uses financial time-series data and it's currently
Need to generate some financial report where the formatting is controlled by the data
i have to build an small app in order to show some data from
I have written a chart that displays financial data. Performance was good while I

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.