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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:22:36+00:00 2026-06-04T17:22:36+00:00

I have a following method: def firstAndLast[CC, A, That](seq: CC)(implicit asSeq: CC => Seq[A],

  • 0

I have a following method:

def firstAndLast[CC, A, That](seq: CC)(implicit asSeq: CC => Seq[A], cbf: CanBuildFrom[CC, A, That]): That = {
  val b = cbf(seq)
  b += seq.head
  b += seq.last
  b.result
}

See: Method taking Seq[T] to return String rather than Seq[Char] for rationale. It works like a charm in the first case but fails to compile in the second:

List("abc", "def") map {firstAndLast(_)}
List("abc", "def") map firstAndLast

Giving:

error: No implicit view available from CC => Seq[A].
List("abc", "def") map firstAndLast

Any idea how to improve this declaration to avoid extra wrapping? Seems like eta-expansion is the problem (?)

  • 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-04T17:22:38+00:00Added an answer on June 4, 2026 at 5:22 pm

    Though they look similar, these are different things:

    List("abc", "def") map {firstAndLast(_)}
    // { x => firstAndLast(x) }
    
    List("abc", "def") map firstAndLast
    // firstAndLast, if it happened to be a function
    

    Now, note how the compiler can easily type x in the first case. In the second case, it is trying to figure out how (seq: CC)(implicit asSeq: CC => Seq[A], cbf: CanBuildFrom[CC, A, That]) might be interpreted as Function1[String, ???], and it is failing because there’s a lot of information missing — namely, the type parameters.

    In other words, in the first case, the compiler first types x, and, therefore, CC, and then tries to figure out the rest. In the second case, the compiler is trying to figure out all of the type parameters at the same time.

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

Sidebar

Related Questions

I have the following method that retrieves all the appointments between 2 dates: def
I have the following method: def call_http_service(url, url_params) begin conn = create_connection(url) resp =
In my messages_controller I have the following private method: def find_message_or_404(slug) message = user.messages.find_by_slug(slug)
I have the following application_controller method: def current_account @current_account ||= Account.find_by_subdomain(request.subdomain) end Should I
I have the following method that is replacing a pound sign from the file
I have the following method that is supposed to be a generic Save to
I have the following method: def speciate chem_formula.each { |chemical| @chem_species = chemical.scan(/[A-Z][^A-Z]*/) puts
I have the following method and want to make it more readable: def value_format(value)
I have the following method on one of my models: def remaining_stock if initial_stock
I have the following method: class Store < ActiveRecord::Base def my_func(str) puts str end

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.