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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:10:16+00:00 2026-05-26T10:10:16+00:00

List(1,2,3,4).sliding(2).map({ case List(a, b) => a < b }).forall(identity) compiles and returns true (albeit

  • 0
List(1,2,3,4).sliding(2).map({ case List(a, b) => a < b }).forall(identity)

compiles and returns true (albeit with a warning that the match is not exhaustive).

List(1,2,3,4).view
   .sliding(2).map({ case List(a: Int, b: Int) => a < b }).forall(identity)

compiles (so long as we include the type annotations for a and b) but throws a MatchError:

scala.MatchError: SeqViewC(...) (of class scala.collection.SeqViewLike$$anon$1)
        at $anonfun$1.apply(<console>:12)
        at $anonfun$1.apply(<console>:12)
        at scala.collection.Iterator$$anon$19.next(Iterator.scala:335)
        at scala.collection.Iterator$class.forall(Iterator.scala:663)
        at scala.collection.Iterator$$anon$19.forall(Iterator.scala:333)

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-26T10:10:17+00:00Added an answer on May 26, 2026 at 10:10 am

    That’s interesting, the list extractor List.unapplySeq is not able to extract SeqViewLike objects, which is why you get a match error. But on the other hand Seq can. You can see that like this:

    scala> val seqView = List(1,2).view.sliding(2).next
    seqView: scala.collection.SeqView[Int,List[Int]] = SeqViewC(...)
    
    scala> val List(a, b, _*) = seqView
    
    scala.MatchError: SeqViewC(...) 
    
    scala> val Seq(a, b, _*) = seqView
    a: Int = 1
    b: Int = 2
    

    So a fix to your second line would be:

    List(1,2,3,4).view.sliding(2).map({ case Seq(a, b) => a < b }).forall(identity)
    // res: Boolean = true
    

    So the issue is that List(1,2,3,4).view returns a SeqView.

    Note that sliding already returns an Iterator, so List(1,2,3,4).sliding(2) is lazy is that sense. May be view is not necessary.

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

Sidebar

Related Questions

I have list of images. I want that user can see images by sliding
List Comprehension for me seems to be like the opaque block of granite that
List Comprehension is a very useful code mechanism that is found in several languages,
List<CertMail> lsRecipetNumber = new List<CertMail>(); CertMail class is in data access layer which returns
According to scaladoc, sliding() returns... An iterator producing iterable collections of size size ,
I have a list of numbers and I'd like to select a sliding window
I have a service that generates a large map through multiple iterations and calculations
Nivo Slider is great for image sliding. I google for list of nivo slider
I was working on a slider using an unordered list. Standard structure, example (not
List<String> nameList = new List<String>(); DropDownList ddl = new DropDownList(); List is populated here,

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.