How to find duplicates in a list?

Try this: val dup = List(1,1,1,2,3,4,5,5,6,100,101,101,102) dup.groupBy(identity).collect { case (x, List(_,_,_*)) => x } The groupBy associates each distinct integer with a list of its occurrences. The collect is basically map where non-matching elements are ignored. The match pattern following case will match integers x that are associated with a list that fits the pattern … Read more

Using return vs. not using return in the list monad

To see why you get the particular answers that arise, the desugaring explanations are very helpful. Let me supplement them with a little general advice about developing perceptions of Haskell code. Haskell’s type system makes no distinction between two separable “moral” purposes: [x] the type of values which are lists with elements drawn from x … Read more

Scala, repeat a finite list infinitely

Very similar to @Eastsun’s, but a bit more intention revealing. Tested in Scala 2.8. scala> val l = List(1, 2, 3) l: List[Int] = List(1, 2, 3) scala> Stream.continually(l.toStream).flatten.take(10).toList res3: List[Int] = List(1, 2, 3, 1, 2, 3, 1, 2, 3, 1) Alternatively, with Scalaz: scala> import scalaz._ import scalaz._ scala> import Scalaz._ import Scalaz._ … Read more

In Haskell, why isn’t there a TypeClass for things that can act like lists?

The ListLike package seems to provide what you’re looking for. I’ve never understood why it isn’t more popular. ListLike aside, one reason this isn’t implemented in the Prelude is because it’s not possible to do so well without invoking some language extensions (multi-param type classes and fundeps or associated types). There are three sorts of … Read more

XPath 1.0 to find if an element’s value is in a list of values

You can check multiple conditions inside the same square brackets: /Location/Addr[State=”TX” or State=”AL” or State=”MA”] Or if you have a really long list, you can create a list of states and use the contains() function. /Location/Addr[contains(‘TX AL MA’, State)] This will work fine for two-letter state abbreviations. If you want to make it more robust … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)