FP
This module contains functional programming methods which can also be found in the FP module of LaScala
Attributes
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
FP.type
Members list
Value members
Concrete methods
Converts a lazy Try[X] into a Future[X].
Converts a lazy Try[X] into a Future[X].
If the Try is a Success, the resulting Future will be successfully completed with the same value. If the Try is a Failure, the resulting Future will be failed with the same exception.
Type parameters
- X
-
the type of the value contained within the
Try.
Value parameters
- xy
-
a lazy computation producing a
Try[X]instance, which may either beSuccesscontaining a value orFailurecontaining an exception.
Attributes
- Returns
-
a
Future[X]that is completed based on the outcome of the providedTry.
Method to make a compatibility check on two vectors (not currently used). The result is successful if the vectors are of the same (non-zero) size.
Method to make a compatibility check on two vectors (not currently used). The result is successful if the vectors are of the same (non-zero) size.
Type parameters
- A
-
the underlying type of as.
- B
-
the underlying type of bs.
Value parameters
- as
-
a vector of As.
- bs
-
a vector of Bs.
Attributes
- Returns
-
a tuple of the two vectors, all wrapped in Try.
Method to make a compatibility check on a vector and a 2-matrix (not currently used). The result is successful if the vectors are of the same (non-zero) size.
Method to make a compatibility check on a vector and a 2-matrix (not currently used). The result is successful if the vectors are of the same (non-zero) size.
Type parameters
- A
-
the underlying type of as.
- B
-
the underlying type of bss.
Value parameters
- as
-
a vector of As, represented as a Seq[A].
- bss
-
a 2-matrix of Bs, represented as a Seq[Seq[B]].
Attributes
- Returns
-
a tuple of the vector and the transpose of the 2-matrix, all wrapped in Try.
Method flatten which takes a Future[Try[X]] and returns a Future[X].
Method flatten which takes a Future[Try[X]] and returns a Future[X].
Type parameters
- X
-
the underlying type.
Value parameters
- executor
-
(implicit) the ExecutionContext
- xyf
-
a Future of Try of X.
Attributes
- Returns
-
a Future[X], which will be successful if the Try was a success, otherwise a failure.
Method to flatten a Try[Future[X]] (not a common occurrence).
Method to flatten a Try[Future[X]] (not a common occurrence).
Type parameters
- X
-
the underlying type.
Value parameters
- executor
-
(implicit) the ExecutionContext
- xfy
-
a Try of Future of X.
Attributes
- Returns
-
a Future[X], which will be successful if the Try was a success, otherwise a failure.
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)
Method to invoke a function (T1,T2)=>R on a tuple (T1, T2).
Method to invoke a function (T1,T2)=>R on a tuple (T1, T2).
Type parameters
- R
-
the type of the result.
- T1
-
the type of the first attribute of t.
- T2
-
the type of the second attribute of t.
Value parameters
- f
-
the function.
- t
-
the tuple.
Attributes
- Returns
-
the result of invoking f on t.
Lifts a function f of type T => R into a function of type T => Try[R]. This allows the application of f to a value of type T while capturing any exceptions that may be thrown during its execution as a Failure. If the function executes successfully, the result is wrapped in a Success.
Lifts a function f of type T => R into a function of type T => Try[R]. This allows the application of f to a value of type T while capturing any exceptions that may be thrown during its execution as a Failure. If the function executes successfully, the result is wrapped in a Success.
Type parameters
- R
-
the output type of the function.
- T
-
the input type of the function.
Value parameters
- f
-
the function to be lifted, of type
T => R.
Attributes
- Returns
-
a new function of type
T => Try[R]that applies the original function and wraps its result in aTry.
Lifts a binary function (T1, T2) => R into a function that returns a Try[R], capturing any exceptions that might occur during its execution.
Lifts a binary function (T1, T2) => R into a function that returns a Try[R], capturing any exceptions that might occur during its execution.
Type parameters
- R
-
the return type of the function.
- T1
-
the type of the first input parameter of the function.
- T2
-
the type of the second input parameter of the function.
Value parameters
- f
-
the binary function to be lifted, of type
(T1, T2) => R.
Attributes
- Returns
-
a new function of type
(T1, T2) => Try[R]that applies the original function and wraps its result in aTry.
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.
Method to take a Map[K,Either[X,V]] and generated a tuple of two sequenced-maps, each of the same form as the input but containing only the left-values or right-values as appropriate. TESTME
Method to take a Map[K,Either[X,V]] and generated a tuple of two sequenced-maps, each of the same form as the input but containing only the left-values or right-values as appropriate. TESTME
Type parameters
- K
-
the key type
- V
-
the value type
- X
-
the partition type
Value parameters
- vXeKm
-
the input map
Attributes
- Returns
-
a tuple of Map[K,Either[X,V]] maps in sequenced form.
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.
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.
Type parameters
- T
-
the underlying type of to.
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.
Converts an Option into a Try, falling back to the given Try if the Option is None.
Converts an Option into a Try, falling back to the given Try if the Option is None.
Type parameters
- T
-
the underlying type of to.
Value parameters
- to
-
the optional value to convert into a
Try. - x
-
the
Tryto fall back to if theOptionisNone.
Attributes
- Returns
-
a
Successcontaining the value from theOptionif it isSome, orxif it isNone.
Method sequence which, applied to a Seq[Try[X]], returns a Try[Seq[X]]
Method sequence which, applied to a Seq[Try[X]], returns a Try[Seq[X]]
Type parameters
- X
-
the underlying type
Value parameters
- xts
-
: Seq[Try[X]]
Attributes
- Returns
-
: Try[Seq[X]]
Method sequence to convert a tuple of A, Try[B] to a Try[(A, B)]
Method sequence to convert a tuple of A, Try[B] to a Try[(A, B)]
Type parameters
- A
-
the underlying type of the _1 element of t.
- B
-
the underlying type of the _2 element of t.
Value parameters
- t
-
the tuple.
Attributes
- Returns
-
a Try of (A, B).
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 anyNones, the result will beNone, otherwiseSome(...). NOTE: that the output collection type will be Seq, regardless of the input type.
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 Iterator of Option[X].
Attributes
- Returns
-
an Option of Iterator[X].
Method sequenceLeft which, given a Map[K,Either[X,V]] (in sequential form), returns a Map[K,X] (also in sequential form) for those elements of the input map which are a (left) X (as opposed to a (right) V).
Method sequenceLeft which, given a Map[K,Either[X,V]] (in sequential form), returns a Map[K,X] (also in sequential form) for those elements of the input map which are a (left) X (as opposed to a (right) V).
Type parameters
- K
-
the key type
- V
-
the value type
- X
-
the partition type
Value parameters
- xVeKs
-
a Map[K,Either[X,V]] (in sequential form)
Attributes
- Returns
-
a Map[K,X] (in sequential form)
Method sequenceLeftRight which, given a Map[K,Either[X,V]], returns a tuple of sequenced maps (each with the same key type), with the X values on the left and the V values on the right.
Method sequenceLeftRight which, given a Map[K,Either[X,V]], returns a tuple of sequenced maps (each with the same key type), with the X values on the left and the V values on the right.
Type parameters
- K
-
the key type
- V
-
the value type
- X
-
the partition type
Value parameters
- vXeKm
-
the map
Attributes
- Returns
-
the separated maps as a tuple of sequenced maps
Method sequenceRight which, given a Map[K,Either[X,V]] (in sequential form), returns a Map[K,V] (also in sequential form) for those elements of the input map which are a (right) V (as opposed to a (left) X).
Method sequenceRight which, given a Map[K,Either[X,V]] (in sequential form), returns a Map[K,V] (also in sequential form) for those elements of the input map which are a (right) V (as opposed to a (left) X).
Type parameters
- K
-
the key type
- V
-
the value type
- X
-
the partition type
Value parameters
- xVeKs
-
a Map[K,Either[X,V]] (in sequential form)
Attributes
- Returns
-
a Map[K,V] (in sequential form)
Method sequence which applied to a Try[X] returns an Either[Throwable,X].
Method sequence which applied to a Try[X] returns an Either[Throwable,X].
Type parameters
- X
-
the underlying type
Value parameters
- xt
-
: Try[X]
Attributes
- Returns
-
: Either[Throwable,X]
Method toMap which takes a tuple of sequenced maps and returns a tuple of actual maps (each map has the same key type but different value types)
Method toMap which takes a tuple of sequenced maps and returns a tuple of actual maps (each map has the same key type but different value types)
Type parameters
- K
-
the key type
- V
-
the value type
- X
-
the partition type
Value parameters
- t
-
the input tuple
Attributes
- Returns
-
the output tuple
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.
Type parameters
- X
-
the underlying type.
Value parameters
- xy
-
the
Tryinstance to be converted.
Attributes
- Returns
-
an
Optioncontaining the value if theTryis aSuccess, 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.
Type parameters
- X
-
the underlying type.
Value parameters
- log
-
a function to log the exception, if any.
- xy
-
the
Tryinstance to be converted.
Attributes
- Returns
-
an
Optioncontaining the value if theTryis aSuccess, orNoneif theTryis aFailure.
Method to convert an Option into a Try, given a default Try to use if the Option is None.
Method to convert an Option into a Try, given a default Try to use if the Option is None.
Type parameters
- X
-
the underlying type of both input and output.
Value parameters
- default
-
a Try[X] to use if
xoisNone. - xo
-
an Option[X].
Attributes
- Returns
-
if
xoisSome(x)thenSuccess(x)elsedefault.
Transforms each element of a tuple by applying the provided functions to its components.
Transforms each element of a tuple by applying the provided functions to its components.
Type parameters
- L1
-
the type of the first element in the input tuple.
- L2
-
the type of the first element in the output tuple.
- R1
-
the type of the second element in the input tuple.
- R2
-
the type of the second element in the output tuple.
Value parameters
- fl
-
a function to transform the first element of the tuple.
- fr
-
a function to transform the second element of the tuple.
- t
-
a tuple containing two elements to be transformed.
Attributes
- Returns
-
a new tuple where the first element is transformed by
fl, and the second byfr.
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.
Type parameters
- X
-
the underlying type.
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 an 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.
Type parameters
- X
-
the underlying type.
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. Unlike whenTry, the computation itself yields a Try[X], so the result is flattened.
Executes the provided computation if the given condition is true; otherwise, returns a Failure. Unlike whenTry, the computation itself yields a Try[X], so the result is flattened.
Type parameters
- X
-
the underlying type.
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.