CanAddAndSubtract

com.phasmidsoftware.number.algebra.core.CanAddAndSubtract
trait CanAddAndSubtract[T <: Structure] extends CanAdd[T, T], CanNegate[T]

A trait that extends CanAdd and provides additional functionality for types supporting both addition and subtraction operations. It introduces the ability to negate instances of type T and override the unary negation operator.

Type Parameters:

  • T: A type extending Structure that supports addition, subtraction, and negation operations with an implicit AdditiveCommutativeGroup[T] evidence.

Attributes

Graph
Supertypes
trait CanNegate[T]
trait CanAdd[T, T]
trait Can[T]
class Object
trait Matchable
class Any
Show all
Known subtypes
class Real
class WholeNumber

Members list

Value members

Abstract methods

def -(that: T)(using AdditiveCommutativeGroup[T]): T

Subtracts the given instance of type T from the current instance.

Subtracts the given instance of type T from the current instance.

This method computes the result of subtracting the that instance from the current instance by utilizing the properties of an additive commutative group defined for type T.

Value parameters

that

the instance of type T to subtract from the current instance

using

evidence of an implicit AdditiveCommutativeGroup[T] that provides the additive commutative group structure supporting subtraction

Attributes

Returns

the resulting value of type T after subtraction

def unary_-: T

Negates the current WholeNumber instance, producing its additive inverse.

Negates the current WholeNumber instance, producing its additive inverse.

Attributes

Returns

The additive inverse of the current WholeNumber.

Inherited methods

def +(that: T)(using AdditiveCommutativeMonoid[T], Convertible[T, T]): T

Adds the given instance of the same type to this instance, leveraging the properties of an AdditiveCommutativeMonoid to ensure associativity, commutativity, and identity. CONSIDER keeping percentage if both are percentages. CONSIDER rewriting this in such a way that no exception will ever be thrown (use compiler to check, not runtime).

Adds the given instance of the same type to this instance, leveraging the properties of an AdditiveCommutativeMonoid to ensure associativity, commutativity, and identity. CONSIDER keeping percentage if both are percentages. CONSIDER rewriting this in such a way that no exception will ever be thrown (use compiler to check, not runtime).

Value parameters

that

The instance of the same type to be added to this instance.

Attributes

Returns

The result of adding this instance and the provided instance.

Inherited from:
CanAdd
def asT: T

Casts the current instance to the type parameter T of the enclosing Can trait.

Casts the current instance to the type parameter T of the enclosing Can trait.

This method performs a type-safe cast using the ClassTag to verify at runtime that the cast is valid. If the current instance cannot be cast to type T, an AlgebraException is thrown.

Attributes

Returns

the current instance as an instance of type T

Throws
AlgebraException

if the cast is invalid

Inherited from:
Can
def negate(using AdditiveCommutativeGroup[T]): T

Computes the additive inverse (negation) of an instance of type T.

Computes the additive inverse (negation) of an instance of type T.

Value parameters

AdditiveCommutativeGroup[T]

an implicit instance of AdditiveCommutativeGroup for the type T, providing the necessary additive group operations.

Attributes

Returns

the negated value of the current instance as an instance of type T.

Inherited from:
CanNegate
infix def plus(that: Structure)(using AdditiveCommutativeMonoid[T]): Option[T]

Computes the addition of this object and the given Structure object using the additive properties of an AdditiveCommutativeMonoid. The operation returns an optional result where the addition succeeds if a valid transformation and combination can be performed.

Computes the addition of this object and the given Structure object using the additive properties of an AdditiveCommutativeMonoid. The operation returns an optional result where the addition succeeds if a valid transformation and combination can be performed.

CONSIDER eliminate this method and use with + instead.

Value parameters

that

the Structure object to be added to this object.

Attributes

Returns

an Option containing the result of the addition if successful, or None if the operation cannot be completed.

Inherited from:
CanAdd

Inherited and Abstract methods

def zero: T

Returns the zero value of type T. This value serves as the identity element for the addition operation of T.

Returns the zero value of type T. This value serves as the identity element for the addition operation of T.

Attributes

Returns

The zero value of type T.

Inherited from:
CanAdd