FP

com.phasmidsoftware.xmldoc.core.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 mapTryGuarded[X, Y](p: X => Boolean, predicate: String = ...)(f: X => Y): Try[X] => Try[Y]

Applies a transformation function to the successful value of a Try if the value satisfies a predicate. If the predicate fails, it returns a Failure with an exception indicating the reason.

Applies a transformation function to the successful value of a Try if the value satisfies a predicate. If the predicate fails, it returns a Failure with an exception indicating the reason.

TESTME

Type parameters

X

the input type of the Try.

Y

the output type after applying the transformation function.

Value parameters

f

a transformation function applied to the value if the predicate passes.

p

a predicate function to test the successful value of the input Try.

predicate

a descriptive string used in the exception message if the predicate fails. Default is "predicate".

Attributes

Returns

a function that transforms a Try[X] to a Try[Y] based on the predicate and transformation function.

def optionToTry[X](xo: Option[X], throwable: Throwable = ...): Try[X]

Converts an Option[X] to a Try[X]. If the Option is Some, it returns a Success containing the value. If the Option is None, it returns a Failure containing the provided or default Throwable.

Converts an Option[X] to a Try[X]. If the Option is Some, it returns a Success containing the value. If the Option is None, it returns a Failure containing the provided or default Throwable.

Type parameters

X

the underlying type of the Option and Try.

Value parameters

throwable

the Throwable to use if the input is None. Defaults to NoSuchElementException.

xo

the input Option[X] to convert.

Attributes

Returns

a Try[X] representing either the success or failure of the conversion.

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

Method to partition an method to combine elements of Try as an Iterator.

Method to partition an method to combine elements of Try as an Iterator.

TESTME

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.

TESTME

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

TESTME

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 sequence[X](xys: Iterator[Try[X]]): Try[Iterator[X]]

Sequence method to combine elements of Try.

Sequence method to combine elements of Try.

TESTME

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

Method to transform a Seq of Try[X] into a Try of Seq[X].

Method to transform a Seq of Try[X] into a Try of Seq[X].

Type parameters

X

the underlying type.

Value parameters

xys

a Seq of Try[X].

Attributes

Returns

a Try of Seq[X].

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

Method to transform a Seq[Option[X]] into an Option[Seq[X]]. NOTE this is pessimistic.

Method to transform a Seq[Option[X]] into an Option[Seq[X]]. NOTE this is pessimistic.

Type parameters

X

the underlying type.

Value parameters

xos

a Seq[Option[X]]].

Attributes

Returns

an Option[Seq[X]] which is defined only if all elements of the input were defined.

def sequenceForgiving[X](f: Throwable => Unit)(xys: Iterable[Try[X]]): Try[Seq[X]]

Method to transform a Seq of Try[X] into a Try of Seq[X].

Method to transform a Seq of Try[X] into a Try of Seq[X].

Non-fatal failures are eliminated from consideration, although each one invokes the function f. Fatal failures are retained so that the result will be a Failure.

Type parameters

X

the underlying type.

Value parameters

f

a function Throwable => Unit which will process each non-fatal failure.

xys

a Seq of Try[X].

Attributes

Returns

a Try of Seq[X].

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.

TESTME

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 tryNotNull[X](x: => X)(msg: String): Try[X]

Attempts to evaluate the provided expression and wraps the result in a Success if it is non-null. If the value is null, a Failure wrapping a NoSuchElementException with the provided message is returned.

Attempts to evaluate the provided expression and wraps the result in a Success if it is non-null. If the value is null, a Failure wrapping a NoSuchElementException with the provided message is returned.

Type parameters

X

the type of the expression's result.

Value parameters

msg

a message to include in the exception if the result is null.

x

a lazily-evaluated expression of type X.

Attributes

Returns

a Try[X] containing Success(x) if x is non-null, or Failure if x is null.

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

def uncurried[T1, T2, T3, T4, T5, T6, R](f: T1 => T2 => T3 => T4 => T5 => T6 => R): (T1, T2, T3, T4, T5, T6) => R

Uncurrying for functions of arity 6.

Uncurrying for functions of arity 6.

Attributes

def uncurried[T1, T2, T3, T4, T5, T6, T7, R](f: T1 => T2 => T3 => T4 => T5 => T6 => T7 => R): (T1, T2, T3, T4, T5, T6, T7) => R

Uncurrying for functions of arity 7.

Uncurrying for functions of arity 7.

Attributes

def uncurried[T1, T2, T3, T4, T5, T6, T7, T8, R](f: T1 => T2 => T3 => T4 => T5 => T6 => T7 => T8 => R): (T1, T2, T3, T4, T5, T6, T7, T8) => R

Uncurrying for functions of arity 8.

Uncurrying for functions of arity 8.

Attributes