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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:05:32+00:00 2026-06-17T11:05:32+00:00

In Scala’s immutable.Queue , there are two methods both named enqueue : /** Creates

  • 0

In Scala’s immutable.Queue, there are two methods both named enqueue:

  /** Creates a new queue with element added at the end
   *  of the old queue.
   *
   *  @param  elem        the element to insert
   */
  def enqueue[B >: A](elem: B) = new Queue(elem :: in, out)

  /** Returns a new queue with all elements provided by an `Iterable` object
   *  added at the end of the queue.
   *
   *  The elements are prepended in the order they are given out by the
   *  iterator.
   *
   *  @param  iter        an iterable object
   */
  def enqueue[B >: A](iter: Iterable[B]) =
    new Queue(iter.toList reverse_::: in, out)

I don’t know how to resolve the ambiguity and call the second one. Here’s what I have tried:

Welcome to Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_07).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import collection.immutable.Queue
import collection.immutable.Queue

scala> val q: Queue[Int] = Queue(1,2,3)
q: scala.collection.immutable.Queue[Int] = Queue(1, 2, 3)

scala> q.enqueue(Iterable(4))
res0: scala.collection.immutable.Queue[Any] = Queue(1, 2, 3, List(4))

scala> q.enqueue[Int](Iterable(4))
<console>:10: error: overloaded method value enqueue with alternatives:
  (iter: scala.collection.immutable.Iterable[Int])scala.collection.immutable.Queue[Int] <and>
  (elem: Int)scala.collection.immutable.Queue[Int]
 cannot be applied to (Iterable[Int])
              q.enqueue[Int](Iterable(4))
                       ^
  • 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-17T11:05:49+00:00Added an answer on June 17, 2026 at 11:05 am

    Tricky, tricky!

    I created a ticket about it. You see, you have been misled by types!

    scala> q.enqueue(scala.collection.Iterable(4))
    res8: scala.collection.immutable.Queue[Any] = Queue(1, 2, 3, List(4))
    
    scala> q.enqueue(scala.collection.immutable.Iterable(4))
    res9: scala.collection.immutable.Queue[Int] = Queue(1, 2, 3, 4)
    

    The Iterable imported by default is the scala.collection.Iterable, which can be either mutable or immutable, but the immutable queue requires the immutable Iterable instead.

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

Sidebar

Related Questions

Scala has both a mutable and an immutable Map , but it has only
Scala collections API is rather nice. The way that both mutable and immutable types
scala> Random.shuffle((1 to 10).toSet) res10: scala.collection.immutable.Set[Int] = Set(5, 10, 1, 6, 9, 2, 7,
scala> val m = Map(1 -> 2) m: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2) scala>
Scala implicits are very powerfull. I'm curious if they are a new/unique feature of
Scala provides immutable collections, such as Set , List , Map . I understand
In Scala, you can overload a method by having methods that share a common
Scala is very elegant in filtering immutable sequences: var l = List(1,2,3,4,5,6) l =
Scala provides a choice of different testing frameworks, but I wonder if there are
In Scala, the partition method splits a sequence into two separate sequences -- those

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.