All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.scalautils.LowPriorityConversionCheckedConstraint.scala Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2001-2013 Artima, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.scalautils

import TripleEqualsSupport._

/**
 * Provides an implicit conversion that will be applied only if a higher-priority implicit conversion declared a subtrait
 * is not applicable.
 *
 * 

* The purpose of this trait is to make the === operator symetric. In other words, a === invocation * will be allowed if an implicit conversion exists in either direction. For example, the implicit widening conversion from * Int to Long will be applied on the left hand side in this expression: *

* *
 * 1 === 1L
 * 
* *

* But in the next expression, it will be applied on the right hand side: *

* *
 * 1L === 1
 * 
* *

* The first expression above is enabled by the implicit conversion conversionCheckedConstraint in traits * ConversionCheckedTripleEquals and * ConversionCheckedLegacyTripleEquals. The second expression above is * enabled by the implicit conversion lowPriorityConversionCheckedConstraint in this trait. *

* *

* The reason these two implicit methods aren't both declared in the subtraits is * that if implicit conversions were available in both directions, they would conflict. By placing one of them in this supertrait, the higher * priority conversion will be selected. *

*/ trait LowPriorityConversionCheckedConstraint extends TripleEqualsSupport { import scala.language.implicitConversions // Inherit the Scaladoc for this method implicit override def lowPriorityConversionCheckedConstraint[A, B](implicit equivalenceOfB: Equivalence[B], cnv: A => B): Constraint[A, B] = new AToBEquivalenceConstraint[A, B](equivalenceOfB, cnv) implicit override def convertEquivalenceToAToBConversionConstraint[A, B](equivalenceOfB: Equivalence[B])(implicit ev: A => B): Constraint[A, B] = new AToBEquivalenceConstraint[A, B](equivalenceOfB, ev) }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy