FP

com.phasmidsoftware.gryphon.util.FP
object FP

General functional programming utilities.

Attributes

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

Members list

Value members

Concrete methods

def assert[T](b: Boolean)(msg: String)(t: T): Try[T]

Asserts a condition and returns a success or failure based on the outcome. If the condition is true, the method returns a success containing the value t. Otherwise, it returns a failure with an AssertionError containing the provided message.

Asserts a condition and returns a success or failure based on the outcome. If the condition is true, the method returns a success containing the value t. Otherwise, it returns a failure with an AssertionError containing the provided message.

Type parameters

T

the type of the value contained in the Try.

Value parameters

b

the condition to be asserted, which determines success or failure.

msg

the error message to include in the AssertionError if the condition is false.

t

the value to be returned in the Success case if the condition is true.

Attributes

Returns

a Try[T] containing the value t as a Success if the condition is true, or a Failure with an AssertionError if the condition is false.

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 lift[A, B](f: A => B): Option[A] => Option[B]

Lifts a function f of type A => B into a function that operates on Option. The resulting function applies the given function f to the value inside an Option if it is defined and returns the transformed Option.

Lifts a function f of type A => B into a function that operates on Option. The resulting function applies the given function f to the value inside an Option if it is defined and returns the transformed Option.

Type parameters

A

the input type of the function f.

B

the output type of the function f.

Value parameters

f

the function to be lifted, which takes a value of type A and returns a value of type B.

Attributes

Returns

a function that takes an Option[A] and returns an Option[B] by applying f to the value inside the Option if it exists.

def mkStringLimit[X](xs: Iterable[X], limit: Int = ..., sep: String = ...): String

Limits the number of elements displayed from an iterable collection when converted to a string. Appends additional information if the size of the collection exceeds the specified limit.

Limits the number of elements displayed from an iterable collection when converted to a string. Appends additional information if the size of the collection exceeds the specified limit.

Type parameters

X

the type of elements in the input collection.

Value parameters

limit

the maximum number of elements to include in the output string.

sep

the separator string to use between elements in the output string (defaults to ", ").

xs

the iterable collection of elements to be processed.

Attributes

Returns

a string representation of up to limit elements from the collection, concatenated with the sep string. If the collection has more elements than the limit, appends a summary of the remaining count.

def mkStringLimitIterator[X](xi: Iterator[X], limit: Int = ..., sep: String = ...): String

Limits the number of elements displayed from an iterable collection when converted to a string. Appends additional information if the size of the collection exceeds the specified limit.

Limits the number of elements displayed from an iterable collection when converted to a string. Appends additional information if the size of the collection exceeds the specified limit.

Type parameters

X

the type of elements in the input collection.

Value parameters

limit

the maximum number of elements to include in the output string.

sep

the separator string to use between elements in the output string (defaults to ", ").

xi

the iterator of elements to be processed.

Attributes

Returns

a string representation of up to limit elements from the collection, concatenated with the sep string. If the collection has more elements than the limit, appends a summary of the remaining count.

def mutableQueueIterator[T](queue: Queue[T]): Iterator[T]

Creates an iterator for a mutable queue that allows sequential access to its elements. Each call to next dequeues an element from the queue, modifying the original queue.

Creates an iterator for a mutable queue that allows sequential access to its elements. Each call to next dequeues an element from the queue, modifying the original queue.

Type parameters

T

the type of elements in the queue.

Value parameters

queue

the mutable queue containing elements of type T to be iterated over. The queue is modified as elements are consumed.

Attributes

Returns

an iterator over the elements of the mutable queue, consuming elements as they are accessed.

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

Method to partition a method to combine elements of Try.

Method to partition a method to combine elements of Try.

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: Seq[Try[X]]): (Seq[Try[X]], Seq[Try[X]])

Method to partition a method to combine elements of Try.

Method to partition a method to combine elements of Try.

TEST

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.

Type parameters

C

a class of the package containing the resourceForClass.

Value parameters

resourceName

the name of the resourceForClass.

Attributes

Returns

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

Try[URL]

def sequence[T](tos: Seq[Option[T]]): Option[Seq[T]]

Combines a sequence of optional values into a single optional sequence, preserving the order of elements and excluding any None values. If the input sequence contains only None values, the result will be None. Some(Nil) will never be returned.

Combines a sequence of optional values into a single optional sequence, preserving the order of elements and excluding any None values. If the input sequence contains only None values, the result will be None. Some(Nil) will never be returned.

Type parameters

T

the type of the elements inside the Option.

Value parameters

tos

the sequence of optional values to be combined.

Attributes

Returns

an Option containing a sequence of all values extracted from the input sequence, or None if there are no such values present.

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

Attributes

Returns

a Try of Iterator[X]

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

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]

def sequence[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 sequence[X](xos: Iterable[Option[X]]): Option[Seq[X]]

Sequence method to combine elements of Try.

Sequence method to combine elements of Try.

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 tee[X](f: X => Unit)(x: => X): X

Applies a side-effecting function f to a lazily evaluated value x, and then returns x.

Applies a side-effecting function f to a lazily evaluated value x, and then returns x.

Type parameters

X

the type of the value being processed.

Value parameters

f

a function that performs a side effect on the value of type X.

x

a lazily evaluated value of type X.

Attributes

Returns

the original value x after the side effect is applied.

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