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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:25:38+00:00 2026-05-26T13:25:38+00:00

According to scaladoc, sliding() returns… An iterator producing iterable collections of size size ,

  • 0

According to scaladoc, sliding() returns…
“An iterator producing iterable collections of size size, except the last and the only element will be truncated if there are fewer elements than size.”

For me, intuitivelly, sliding(n) would return a sliding window of n elements if available. With the current implementation, I need to perform an extra check to make sure I don’t get a list of 1 or 2 elements.

scala> val xs = List(1, 2)
xs: List[Int] = List(1, 2)

scala> xs.sliding(3).toList
res2: List[List[Int]] = List(List(1, 2))

I expected here an empty list instead. Why is sliding() implemented this way instead?

  • 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-26T13:25:38+00:00Added an answer on May 26, 2026 at 1:25 pm

    It was a mistake, but wasn’t fixed as of 2.9. Everyone occasionally makes design errors, and once one gets into the library it’s a nontrivial task to remove it.

    Workaround: add a filter.

    xs.sliding(3).filter(_.size==3).toList
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to PHP.net manual, pg_pconnect will create a persistent connection, or will return the
According to what I've heard, integer values that are not the processor's word size
According to be Spring Framework documentation, logging is the only mandatory dependency of Spring.
According to the dataset specification , how is element.dataset meant to delete data attributes?
According to the HttpListener reference , a call to HttpListener.GetContext will block until it
According Mac App Store rules 2.30: Program may write only to allowed locations. My
According to Scaladoc, there is no method named map in Array class, but there
According to the manual , git dcommit will create a revision in SVN for
According to the introduction about ReaderT , I can only find: ReaderT Env IO
According to this SO post: What is the size of an enum in C?

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.