- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
2.8 collections: containsSlice deprecated. why?
Thu, 2009-07-23, 00:45
scala> "foobar" containsSlice "oba"
:5: warning: method containsSlice in trait SequenceTemplate is deprecated: Should be repaced by indexOf(that) != -1
"foobar" containsSlice "oba"
^
res2: Boolean = false
having to test against -1 seems like a big step backwards to me.
if we can't have containsSlice back, how about at least using
Option[Int] instead of a -1 return?
(I just noticed that also, the answer is wrong! I opened a ticket on
that, http://lampsvn.epfl.ch/trac/scala/ticket/2186)
Fri, 2009-07-24, 19:37
#2
Re: 2.8 collections: containsSlice deprecated. why?
Ian Clarke wrote:
> For example, List.head, List.last, List.tail - all throw exceptions in
> the event of an empty list. Shouldn't they be returning Options?
>
No, you're supposed to use pattern matching instead. :)
-0xe1a
Sat, 2009-07-25, 00:37
#3
Re: 2.8 collections: containsSlice deprecated. why?
On Fri, Jul 24, 2009 at 1:17 PM, Alex Cruise wrote:
> Ian Clarke wrote:
>>
>> For example, List.head, List.last, List.tail - all throw exceptions in
>> the event of an empty list. Shouldn't they be returning Options?
>>
>
> No, you're supposed to use pattern matching instead. :)
How do you pattern match for the last item in a list?
Ian.
Sat, 2009-07-25, 00:47
#4
Re: 2.8 collections: containsSlice deprecated. why?
reverse and match on the head
On Sat, Jul 25, 2009 at 12:26 AM, Ian Clarke <ian.clarke@gmail.com> wrote:
On Sat, Jul 25, 2009 at 12:26 AM, Ian Clarke <ian.clarke@gmail.com> wrote:
On Fri, Jul 24, 2009 at 1:17 PM, Alex Cruise<alex@cluonflux.com> wrote:
> Ian Clarke wrote:
>>
>> For example, List.head, List.last, List.tail - all throw exceptions in
>> the event of an empty list. Shouldn't they be returning Options?
>>
>
> No, you're supposed to use pattern matching instead. :)
How do you pattern match for the last item in a list?
Ian.
--
Ian Clarke
CEO, Uprizer Labs
Email: ian@uprizer.com
Ph: +1 512 422 3588
Fax: +1 512 276 6674
Sat, 2009-07-25, 00:57
#5
Re: 2.8 collections: containsSlice deprecated. why?
On Friday July 24 2009, Ian Clarke wrote:
> On Fri, Jul 24, 2009 at 1:17 PM, Alex Cruise wrote:
> > Ian Clarke wrote:
> >> For example, List.head, List.last, List.tail - all throw
> >> exceptions in the event of an empty list. Shouldn't they be
> >> returning Options?
> >
> > No, you're supposed to use pattern matching instead. :)
>
> How do you pattern match for the last item in a list?
someList match {
case Nil => // someList is empty
case last :: Nil => // last is the last element
case first :: more => // first is the head, more is a non-empty remainder
}
> Ian.
Randall Schulz
On Wed, Jul 22, 2009 at 6:43 PM, Seth Tisue wrote:
> having to test against -1 seems like a big step backwards to me.
> if we can't have containsSlice back, how about at least using
> Option[Int] instead of a -1 return?
Indeed. I notice many other places in the standard API where
Option[A] should be returned, but instead an exception is thrown.
For example, List.head, List.last, List.tail - all throw exceptions in
the event of an empty list. Shouldn't they be returning Options?
Ian.