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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:50:40+00:00 2026-06-02T05:50:40+00:00

Optional method is method which can be applied if class generics has specific type.

  • 0

Optional method is method which can be applied if class generics has specific type.
examples:

list.unzip //works only if this is collection of pairs
list.sum //works only if this collection of numbers

Currently I want implement regression method which has the same constraints as unzip(i.e. collection of 2d points) but I don’t know how to make sure that method (implicit asPair: A => (A1, A2) exsist and where the best place to define such conversions.

  • 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-02T05:50:43+00:00Added an answer on June 2, 2026 at 5:50 am

    Here’s what TraversableOnce.toMap does to ensure it is only called on a collection of pairs.

    def toMap[T, U](implicit ev: A <:< (T, U)): immutable.Map[T, U] = {
      val b = immutable.Map.newBuilder[T, U]
      for (x <- self)
        b += x
      b.result
    }
    

    But if you are looking to add a similar method to an existing collection class, you can make it even easier:

    class EnhancedIterable[T,U](x: Iterable[(T,U)]) { // CanBuildFrom omitted for brevity
      def swapAll() = x.map(_.swap)
    }
    implicit def enhanceIterable[T,U](x: Iterable[(T,U)]) = new EnhancedIterable(x)
    
    List((1,2), (3,4), (5,6)).swapAll // List((2,1), (4,3), (6,5))
    List(1, 2, 3).swapAll // error: value swapAll is not a member of List[Int]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know the XMLHttpRequest object supports a method open which has an optional parameter
How can I create a jQuery function like $.MyFunction(/*optional parameter*/)? which will return a
I'm building a query that has a bunch of optional parameters, some of which
I'm trying in different ways to create a small scrolling method which can take
I am implementing an optional delegate method on the Cocoa Touch API. What I
any idea how (if even possible) to call java method with optional parameters from
I added 3 optional boolean parameters to a method found within a VB6 DLL.
I'm adding optional OpenID authentication to the system. Everything works smoothly with DotNETOpenID. Yet,
when the optional parameters are null or empty how can i ignore that condition?
C#4.0 brings optional parameters, which I've been waiting for for quite some time. However

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.