Example #1
0
        /// <summary>
        /// Determines whether this map is equal to a sequence of key-value pairs. Maps are equal if they contain the same keys, and if the values associated with them are also equal.
        /// </summary>
        /// <param name="other">A sequence of key-value pairs. This operation is much faster if it's a map compatible with this one.</param>
        /// <param name="equality">A function for determining equality between values.</param>
        /// <returns></returns>
        public virtual bool MapEquals(IEnumerable <KeyValuePair <TKey, TValue> > other, Func <TValue, TValue, bool> equality)
        {
            other.CheckNotNull("other");
            equality.CheckNotNull("equality");
            var boiler = EqualityHelper.BoilerEquality(this, other);

            if (boiler.IsSome)
            {
                return(boiler.Value);
            }
            var map = other as TMap;

            if (map != null && IsCompatibleWith(map))
            {
                return(MapEquals(map, equality));
            }
            var tryLength = other.TryGuessLength();

            if (tryLength.IsSome && tryLength.Value < Length)
            {
                return(false);
            }

            return(other.ForEachWhile(kvp => {
                var myValue = this.TryGet(kvp.Key);
                return myValue.IsSome && equality(myValue.Value, kvp.Value);
            }));
        }
Example #2
0
        public bool Equals(T x, T y)
        {
            var boiler = EqualityHelper.BoilerEquality(x, y);

            if (boiler.IsSome)
            {
                return(boiler.Value);
            }
            return(EqualityFunction(x, y));
        }
Example #3
0
        /// <summary>
        ///     Determines structural equality between the sequential collections.
        /// </summary>
        /// <param name="a">The first collection</param>
        /// <param name="b">The second collection.</param>
        /// <returns>
        ///     Whether the two collections are equal.
        /// </returns>
        public static bool operator ==(AbstractSequential <TElem, TList> a, AbstractSequential <TElem, TList> b)
        {
            var boiler = EqualityHelper.BoilerEquality(a, b);

            if (boiler.IsSome)
            {
                return(boiler.Value);
            }
            return

                (a.Equals(b));
        }