[nem-en] Extension methods

Kamil Skalski kamil.skalski at gmail.com
Tue Jan 31 21:19:10 CET 2006


>
> I will correct as soon as possible the SkipWhile
> method. Equals<T> just follws the spec, which tells
> that objects must be compared using both Equals and
> GetHashCode methods. I just followed it ;-)
>

Hm, but it IS a little bit strange that Equals requires any of Equals
to return true OR hashcodes to be equal. I don't know which spec are
you referring to, but IMHO it was ment to be Equals --> true AND
hashcodes equal.


> Thanks,
> trupill
>
>  --- Marcin 'Qrczak' Kowalczyk <qrczak at knm.org.pl>
> escribió:
>
> > Alejandro Serrano <trupill at yahoo.es> writes:
> >
> > > I attach a C# implementation of System.Query to
> > start thinking about
> > > query-like expressions.
> >
> > Anybody has tested it? I browsed it just for
> > curiosity, and found
> > e.g. this in System.Query/SequencePartitioning.cs:
> >
> >
> > [System.Runtime.CompilerServices.Extension]
> >                 public static IEnumerable<T>
> > SkipWhile<T> (
> >                         IEnumerable<T> source,
> >                         Func<T, bool> predicate)
> >                 {
> >                         if (source == null ||
> > predicate == null)
> >                                 throw new
> > ArgumentNullException ();
> >
> >                         bool yield = false;
> >
> >                         foreach (T element in
> > source) {
> >                                 if (yield)
> >                                         yield return
> > element;
> >                                 else
> >                                         if
> > (!predicate (element))
> >
> > yield = true;
> >                         }
> >                 }
> >
> > which doesn't yield the first element which doesn't
> > satisfy the
> > predicate, or this in
> > System.Query/SequenceNotInSpec.cs:
> >
> >
> > [System.Runtime.CompilerServices.Extension]
> >                 private static bool Equals<T> (
> >                         T first, T second)
> >                 {
> >                         // Mostly, values in
> > Enumerable<T>
> >                         // sequences need to be
> > compared using
> >                         // Equals and GetHashCode
> >
> >                         if (first == null || second
> > == null)
> >                                 return (first ==
> > null && second == null);
> >                         else
> >                                 return
> > ((first.Equals (second) ||
> >
> > first.GetHashCode () == second.GetHashCode ()));
> >                 }
> >
> > where comparing hash codes doesn't seem to make
> > sense.
> >
> > --
> >    __("<         Marcin Kowalczyk
> >    \__/       qrczak at knm.org.pl
> >     ^^     http://qrnik.knm.org.pl/~qrczak/
> >
> > _______________________________________________
> > https://nemerle.org/mailman/listinfo/devel-en
> >
>
>
>
>
>
>
> ______________________________________________
> LLama Gratis a cualquier PC del Mundo.
> Llamadas a fijos y móviles desde 1 céntimo por minuto.
> http://es.voice.yahoo.com
>
> _______________________________________________
> https://nemerle.org/mailman/listinfo/devel-en
>


--
Kamil Skalski
http://nazgul.omega.pl



More information about the devel-en mailing list