FP

com.phasmidsoftware.tableparser.core.util.FP
object FP

Various utilities for functional programming.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
FP.type

Members list

Value members

Concrete methods

def indexFound(w: String, i: Int): Try[Int]

Method to determine if the String w was found at a valid index (i).

Method to determine if the String w was found at a valid index (i).

Value parameters

i

the index found.

w

the String (ignored unless there's an exception).

Attributes

Returns

Success(i) if all well, else Failure(exception).

def partition[X](xys: Iterator[Try[X]]): (Iterator[Try[X]], Iterator[Try[X]])

Method to partition an Iterator.

Method to partition an Iterator.

Type parameters

X

the underlying type.

Value parameters

xys

an Iterator of Try[X].

Attributes

Returns

a tuple of two iterators of Try[X], the first one being successes, the second one being failures.

def partition[X](xys: Iterable[Try[X]]): (Iterable[Try[X]], Iterable[Try[X]])

Method to partition an method to combine elements of Try.

Method to partition an method to combine elements of Try.

Type parameters

X

the underlying type.

Value parameters

xys

a Seq of Try[X].

Attributes

Returns

a tuple of two Seqs of Try[X], the first one being successes, the second one being failures.

def recoverOption[X](xy: => Try[Option[X]])(f: Throwable => Unit): Option[X]

Attempts to recover the value from a computation represented as a lazy Try[Option[X]]. If the computation succeeds, it returns the contained Option[X]. If the computation fails with a non-fatal exception, the exception is passed to the provided recovery function, and the result is None. Fatal exceptions are rethrown.

Attempts to recover the value from a computation represented as a lazy Try[Option[X]]. If the computation succeeds, it returns the contained Option[X]. If the computation fails with a non-fatal exception, the exception is passed to the provided recovery function, and the result is None. Fatal exceptions are rethrown.

Type parameters

X

The underlying type of the Option.

Value parameters

f

A function to handle non-fatal exceptions encountered during evaluation of xy.

xy

A lazy computation resulting in a Try[Option[X]]. It is evaluated when the method is invoked.

Attributes

Returns

The Option[X] value if successful, None if a non-fatal exception occurs, or the exception is rethrown if it is fatal.

def resource[C : ClassTag](resourceName: String): Try[URL]

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].

def resourceForClass(resourceName: String, clazz: Class[_] = ...): 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]

def sampler[X](n: Int)(using r: Random): X => Boolean

Method to return a random sampling function.

Method to return a random sampling function.

Type parameters

X

the underlying type of the sampler.

Value parameters

n

this is the sample factor: approximately one in every n successful results will form part of the result.

r

(implicit) Random source of entropy.

Attributes

Returns

an X => Boolean function which is always yields false if its input is a failure, otherwise, it chooses every nth value (approximately).

def sequence[X](xys: Iterator[Try[X]]): Try[Iterator[X]]

Sequence method to combine elements of Try.

Sequence method to combine elements of Try.

CONSIDER invoking sequenceRev

Type parameters

X

the underlying type

Value parameters

xys

an Iterator of Try[X]

Attributes

Returns

a Try of Iterator[X]

def sequence[X](xys: Iterable[Try[X]]): Try[Seq[X]]

Sequence method to combine elements of Try while retaining their original order.

Sequence method to combine elements of Try while retaining their original order.

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

def sequence[X](xos: Iterable[Option[X]]): Option[Seq[X]]

Sequence method to combine elements of type Option[X]. The result is not defined unless all/any? of the elements are defined.

Sequence method to combine elements of type Option[X]. The result is not defined unless all/any? of the elements are defined.

NOTE that the order of the resulting values will be the reverse of the input. This is for performance reasons.

Type parameters

X

the underlying type.

Value parameters

xos

an Iterable of Option[X].

Attributes

Returns

an Option of Seq[X]. NOTE: that the output collection type will be Seq, regardless of the input type CONSIDER using Builder

def sequence[X](xos: Iterator[Option[X]]): Option[Seq[X]]

Sequence method to combine elements of Option[X]. The result is defined unless all the elements are None.

Sequence method to combine elements of Option[X]. The result is defined unless all the elements are None.

NOTE that the order of the resulting values will be the reverse of the iterator. This is for performance reasons.

Type parameters

X

the underlying type.

Value parameters

xos

an Iterable of Option[X].

Attributes

Returns

an Option of Seq[X]. NOTE: that the output collection type will be Seq, regardless of the input type

def sequenceForgiving[X](xys: Iterable[Try[X]]): Try[Seq[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

def sequenceForgivingTransform[X](xys: Iterable[Try[X]])(fSuccess: X => Try[Option[X]], pfFailure: PartialFunction[Throwable, Try[Option[X]]]): Try[Seq[X]]

Sequence method to combine elements of Try.

Sequence method to combine elements of Try.

Type parameters

X

the underlying type.

Value parameters

fSuccess

a function of type X => Try of Option[X].

pfFailure

a partial function of type Throwable => Try of Option[X].

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

def sequenceForgivingWith[X](xys: Iterable[Try[X]])(pfFailure: PartialFunction[Throwable, Try[Option[X]]]): Try[Seq[X]]

Sequence method to combine elements of Try.

Sequence method to combine elements of Try.

Type parameters

X

the underlying type.

Value parameters

pfFailure

a partial function of type Throwable => Try of Option[X].

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

def sequenceInc[X](xos: Iterable[Option[X]]): Option[Seq[X]]

Sequence (inclusive) method to combine elements of type Option[X]. The result is defined unless all the elements are None.

Sequence (inclusive) method to combine elements of type Option[X]. The result is defined unless all the elements are None.

NOTE that the order of the resulting values will be the reverse of the input. This is for performance reasons.

Type parameters

X

the underlying type.

Value parameters

xos

an Iterable of Option[X].

Attributes

Returns

an Option of Seq[X]. NOTE: that the output collection type will be Seq, regardless of the input type

def sequenceRev[X](xys: Iterable[Try[X]]): Try[Seq[X]]

Sequence method to combine elements of Try.

Sequence method to combine elements of Try.

NOTE: this method is much faster than sequence but does return the elements in their reverse order.

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

def tryToOption[X](f: Throwable => Unit)(xy: Try[X]): Option[X]

Method to transform a Try[X] into an Option[X]. But, unlike "toOption," a Failure can be logged.

Method to transform a Try[X] into an Option[X]. But, unlike "toOption," a Failure can be logged.

Type parameters

X

the underlying type.

Value parameters

f

a function to process any Exception (typically a logging function).

xy

the input Try[X].

Attributes

Returns

an Option[X].