FP
This module is concerned with the generic operations for operating on Numbers. TODO resolve duplication. NOTE this is similar (maybe idential) to core.misc.FP.
Attributes
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
FP.type
Members list
Value members
Concrete methods
This method and optionMap are (almost) twins (working for Try and Option respectively). To yield the (tried) result, we map the right-hand member of the input (lRe) with a function rToZ. The result of this is then pattern-matched: In the Some(z) case, we return the Success(z). In the None case, we return the result of tryMapLeft applied to the lRe with the function l2Zy.
This method and optionMap are (almost) twins (working for Try and Option respectively). To yield the (tried) result, we map the right-hand member of the input (lRe) with a function rToZ. The result of this is then pattern-matched: In the Some(z) case, we return the Success(z). In the None case, we return the result of tryMapLeft applied to the lRe with the function l2Zy.
NOTE: in practice, this does not seem to be used (and is untested), but it should remain here.
Type parameters
- L
-
the type of the left-side of the Either.
- R
-
the type of the right-side of the Either.
- Z
-
the underlying type of the result.
Value parameters
- l2Zy
-
a function L => Try[Z]
- lRe
-
the input, an Either[L,R].
- r2Z
-
a function R => Z.
Attributes
- Returns
-
a Try[Z]
Terminates the computation by producing a failure encapsulated in a Try instance.
Terminates the computation by producing a failure encapsulated in a Try instance.
Value parameters
- s
-
The error message to be included in the exception.
Attributes
- Returns
-
A Try instance containing a failure with an AlgebraException initialized with the provided error message.
- Note
Creates a failed instance of Try containing the provided exception.
Creates a failed instance of Try containing the provided exception.
Value parameters
- e
-
The
Throwablerepresenting the failure reason.
Attributes
- Returns
-
A
Failurewrapping the given exception.
This method is a substitute for Try.apply in the case that we want it as a function (otherwise, we run into a type inference problem).
This method is a substitute for Try.apply in the case that we want it as a function (otherwise, we run into a type inference problem).
Type parameters
- X
-
the type of x.
Value parameters
- x
-
an X.
Attributes
- Returns
-
Success(x)
This method and tryMap are (almost) twins (working for Option and Try respectively -- although there are a few differences other than the monad type). To yield the (optional) result, we map the right-hand member of the input (lRe) with a function rToZ. We return either the result or, if empty, then the result of flatMap applied to the left member with a function lToZo.
This method and tryMap are (almost) twins (working for Option and Try respectively -- although there are a few differences other than the monad type). To yield the (optional) result, we map the right-hand member of the input (lRe) with a function rToZ. We return either the result or, if empty, then the result of flatMap applied to the left member with a function lToZo.
Type parameters
- L
-
the type of the left-side of the Either.
- R
-
the type of the right-side of the Either.
- Z
-
the underlying type of the result.
Value parameters
- l2Zo
-
a function L => Option[Z].
- lRe
-
the input, an Either[L,R].
- r2Z
-
a function R => Z.
Attributes
- Returns
-
an Option[Z]
Method to yield an Option of T according to whether the predicate p yields true.
Method to yield an Option of T according to whether the predicate p yields true.
Type parameters
- T
-
the type of t (and the underlying type of the result).
Value parameters
- p
-
a predicate on T.
- t
-
an actual value of T.
Attributes
- Returns
-
Some(t) if p(t) is true, otherwise None.
Computes the power of a given number by raising it to the specified exponent.
Computes the power of a given number by raising it to the specified exponent.
CONSIDER moving this somewhere else more aligned to Numeric ops
Value parameters
- n
-
the exponent to which the base number is raised
- x
-
the base number
Attributes
- Returns
-
the result of raising the base number to the specified exponent
Reads data from a specified resource file, applies a transformation function to each line, and converts the resulting values into a sequence of BigInt objects.
Reads data from a specified resource file, applies a transformation function to each line, and converts the resulting values into a sequence of BigInt objects.
Value parameters
- filename
-
the name of the resource file to read from
- function
-
a function that takes an array of strings (split from a line) and returns an optional string result after processing
Attributes
- Returns
-
a
Trycontaining a sequence of BigInt values if successful, or a failure if an error occurs during processing or if the file contains invalid input
Method to convert a None value to a given exception (rather than the NoSuchElement exception).
Method to convert a None value to a given exception (rather than the NoSuchElement exception).
Type parameters
- T
-
the underlying type of to.
Value parameters
- to
-
an Option[T].
- x
-
a Throwable to be thrown if to is None.
Attributes
- Returns
-
t if to is Some(t); otherwise x will be thrown.
- Note
-
Throws java.lang.Throwable x
Converts an Option into a Try, providing a failure cause if the Option is None.
Converts an Option into a Try, providing a failure cause if the Option is None.
Value parameters
- to
-
The optional value to convert into a
Try. - x
-
The throwable to use as the failure cause if the
OptionisNone.
Attributes
- Returns
-
A
Successcontaining the value from theOptionif it isSome, or aFailureif it isNone.
Method to yield a URL for a given resourceForClass in the classpath for C.
Method to yield a URL for a given resourceForClass in the classpath for C.
Type parameters
- C
-
a class of the package containing the resourceForClass.
Value parameters
- resourceName
-
the name of the resourceForClass.
Attributes
- Returns
-
a Try[URL].
Method to yield a Try[URL] for a resource name and a given class.
Method to yield a Try[URL] for a resource name and a given class.
Value parameters
- clazz
-
the class, relative to which, the resource can be found (defaults to the caller's class).
- resourceName
-
the name of the resource.
Attributes
- Returns
-
a Try[URL]
Sequence method to combine elements of Try.
Sequence method to combine elements of Try.
Type parameters
- X
-
the underlying type
Value parameters
- xys
-
an Iterator of Try[X]
Attributes
- Returns
-
a Try of Iterator[X]
Sequence method to combine elements of Try.
Sequence method to combine elements of Try.
Type parameters
- X
-
the underlying type
Value parameters
- xys
-
an Iterable of Try[X]
Attributes
- Returns
-
a Try of Seq[X] NOTE: that the output collection type will be Seq, regardless of the input type
Sequence method to combine elements of Try.
Sequence method to combine elements of Try.
Type parameters
- X
-
the underlying type
Value parameters
- xos
-
an Iterator of Try[X]
Attributes
- Returns
-
a Try of Iterator[X]
Sequence method to invert the order of types Option/Try.
Sequence method to invert the order of types Option/Try.
Type parameters
- X
-
the underlying type.
Value parameters
- xyo
-
an Option of Try[X].
Attributes
- Returns
-
a Try of Option[X].
Sequence method to combine elements of type Option[X].
Sequence method to combine elements of type Option[X].
Type parameters
- X
-
the underlying type.
Value parameters
- xos
-
an Iterable of Option[X].
Attributes
- Returns
-
if
xoscontains any Nones, the result will be None, otherwise Some(...). NOTE: that the output collection type will be Seq, regardless of the input type
Converts a Try instance into an Option. Any Exception in the input is, of course, lost.
Converts a Try instance into an Option. Any Exception in the input is, of course, lost.
Value parameters
- xy
-
The
Tryinstance to be converted.
Attributes
- Returns
-
An
Optioncontaining the value if theTryis a Success, orNoneif theTryis aFailure.
Converts a Try instance into an Option. Any Exception in the input is logged according to the log function.
Converts a Try instance into an Option. Any Exception in the input is logged according to the log function.
Value parameters
- xy
-
The
Tryinstance to be converted.
Attributes
- Returns
-
An
Optioncontaining the value if theTryis a Success, orNoneif theTryis aFailure.
Method to convert an Option into a Try.
Method to convert an Option into a Try.
Type parameters
- X
-
the underlying type of both input and output.
Value parameters
- default
-
a
Try[X]. - xo
-
an
Option[X].
Attributes
- Returns
-
if
xoisSome(x)thenSuccess(x)elsedefault.
Method to convert an Option into a Try where the default is a String.
Method to convert an Option into a Try where the default is a String.
Type parameters
- X
-
the underlying type of both input and output.
Value parameters
- default
-
a
Throwable. - xo
-
an
Option[X].
Attributes
- Returns
-
if
xoisSome(x)thenSuccess(x)elseFailure(RationalException(default)).
Method to convert an Option into a Try where the default is an exception, i.e., a Throwable.
Method to convert an Option into a Try where the default is an exception, i.e., a Throwable.
Type parameters
- X
-
the underlying type of both input and output.
Value parameters
- default
-
a
Throwable. - xo
-
an
Option[X].
Attributes
- Returns
-
if
xoisSome(x)thenSuccess(x)elseFailure(default).
Method to yield a partially lifted version of a Function1 as a function.
Method to yield a partially lifted version of a Function1 as a function.
Type parameters
- X
-
the type of the input to f and the input to the resulting function.
- Z
-
the type of the output from f and the underlying type of the resulting function.
Value parameters
- f
-
an X => Z.
Attributes
- Returns
-
a function X => Try[Z]
Method to yield a partially lifted version of a Function2 as a function.
Method to yield a partially lifted version of a Function2 as a function.
Type parameters
- X
-
the type of the first input to f and of the resulting function.
- Y
-
the type of the second input to f and of the resulting function.
- Z
-
the type of the output from f and the underlying type of the resulting function.
Value parameters
- f
-
an (X,Y) => Z.
Attributes
- Returns
-
a function X => Try[Z]
This method is similar to doMap but with some important differences. To yield the (tried) result, we map the right-hand member of the input (lRe) with a function rToZy. The result of this is then pattern-matched: In the case of Some(Success(z)), we return the Success(z). In the case of Some(Failure), we invoke tryMapLeft with the transpose of lRe and the function l2Zy. In the case of None, we return the result of tryMapLeft applied to the lRe with the function l2Zy.
This method is similar to doMap but with some important differences. To yield the (tried) result, we map the right-hand member of the input (lRe) with a function rToZy. The result of this is then pattern-matched: In the case of Some(Success(z)), we return the Success(z). In the case of Some(Failure), we invoke tryMapLeft with the transpose of lRe and the function l2Zy. In the case of None, we return the result of tryMapLeft applied to the lRe with the function l2Zy.
Type parameters
- L
-
the type of the left-side of the
Either. - R
-
the type of the right-side of the
Either. - Z
-
the underlying type of the result.
Value parameters
- l2Zy
-
a function
L => Try[Z]. - lRe
-
the input, an
Either[L,R]. - r2L
-
an (implicit) converter from
RtoL. - r2Zy
-
a function
R => Try[Z].
Attributes
- Returns
-
a
Try[Z]
Executes the provided computation if the given condition is true; otherwise, returns a Failure.
Executes the provided computation if the given condition is true; otherwise, returns a Failure.
Value parameters
- p
-
A Boolean condition that determines whether the computation should be executed.
- x
-
A computation represented as a call-by-name parameter, which returns a Try[X] when evaluated.
Attributes
- Returns
-
A Try[X] representing the result of the computation if the condition is true, or a Failure if the condition is false.
Executes the provided block of code conditionally based on the given boolean predicate. If the predicate is true, the block of code is executed and its result is returned. If the predicate is false, None is returned.
Executes the provided block of code conditionally based on the given boolean predicate. If the predicate is true, the block of code is executed and its result is returned. If the predicate is false, None is returned.
Value parameters
- p
-
the boolean predicate that determines whether the block of code should be executed
- x
-
a by-name parameter representing the block of code returning an Option of type X
Attributes
- Returns
-
an Option containing the result of the block of code if
pis true, or None ifpis false
Executes the provided computation if the given condition is true; otherwise, returns a Failure.
Executes the provided computation if the given condition is true; otherwise, returns a Failure.
Value parameters
- p
-
A Boolean condition that determines whether the computation should be executed.
- x
-
A computation represented as a call-by-name parameter, which returns a Try[X] when evaluated.
Attributes
- Returns
-
A Try[X] representing the result of the computation if the condition is true, or a Failure if the condition is false.