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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:56:46+00:00 2026-05-16T16:56:46+00:00

I was writing a class that contained some functional-esque methods. First I wrote them

  • 0

I was writing a class that contained some functional-esque methods. First I wrote them using List as parameters and return types. Then I thought “Hey, you could also use a more generic type!” so I replaced the Lists with Seq, hoping that I could make my stuff faster one day by feeding them something else than lists.

So which general purpose stack-like data-structure shall I write my methods and algorithms for? Is there a general pattern I can stick to? All this is because the methods might need to get optimized in the future in case they will form a bottle-neck.

Update

I’ll try to be a bit more precise:
Given you know which operations you are using, like reversing, .tail, direct element access, or for comprehensions. Can I choose a type that will force efficiency on those operations?

Update 2

I’m quite aware of the performance of concrete data structures for various tasks. What I’m not aware of is which data structure might appear as a sub-class of some super type.

For example shall I use TraversableOnce or IndexedSeq instead of List or Array? Will it buy me anything?

Additional Question

What is your default List-like data-structure signature? Do you write

def a(b: List[A]): List[A] 

or

def a(b: TraversableOnce[A]): TraversableOnce[A]

Can you explain why?

  • 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-05-16T16:56:47+00:00Added an answer on May 16, 2026 at 4:56 pm

    I think, in general, you should use Seq for your parameters and design your methods to work efficiently with List. This way your methods will work ok with most Seq implementations and you will not have to convert your seqs prior to use your methods.

    Edit

    Your question has many questions inside.

    1. So which general purpose stack-like data-structure shall I write my methods and algorithms for?
      • I think the answer here is List. It’s a stack and it’s very fast
    2. Can I choose a type that will force efficiency on those operations?
      • In general you’ll have to rely on a concerete implementation. The performance characteristics are here http://www.scala-lang.org/docu/files/collections-api/collections_40.html
    3. For example shall I use TraversableOnce or IndexedSeq instead of List or Array? Will it buy me anything?
      • Some abstractions have performance characteristics defined, some others don’t. For example IndexedSeq scaladoc says “Indexed sequences support constant-time or near constant-time element access and length computation”. If you have an IndexedSeq parameter and someone passes an IndexedSeq implementation that does not have “near-constant time element access”, then that someone is breaking the contract and it’s not your problem.
    4. What is your default List-like data-structure signature?
      • Seq
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a factory class that should be able to return singleton instances of
first of all, a preface: I'm writing a java class that creates temporary tables
I'm writing a library class to encapsulate some of my logic in my first
I'm writing a class for solving sudoku puzzles that has some two dimensional arrays
I am writing a class in Python 2.6.2 that contains a lookup table. Most
I'm writing a C++ class for a book that contains a name: class Book
I am writing a class that I know that needs a lock, because the
I'm writing a class that returns both a DataTable and a IEnumerable. I cannot
I'm writing a class that extends a UIScrollView to display a large tiled image,
I am writing a class that inherits from IHttpHandler for script and css combining.

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.