TryUsing

com.phasmidsoftware.gryphon.util.TryUsing
object TryUsing

Utility object to provide resource management methods using the Using construct.

The methods in this object ensure proper handling of resources by automatically closing or releasing them after they are used within a defined context.

Attributes

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

Members list

Value members

Concrete methods

def apply[R : Releasable, A](resource: => R)(f: R => Try[A]): Try[A]

This method is to Using.apply as flatMap is to Map.

This method is to Using.apply as flatMap is to Map.

Type parameters

A

the underlying type of the result.

R

the resource type.

Value parameters

f

a function of R => Try[A].

resource

a resource which is used by f and will be managed via Using.apply

Attributes

Returns

a Try[A]

def trial[R : Releasable, A](ry: => Try[R])(f: R => A): Try[A]

Executes the provided function f with a resource managed via Using while handling the resource lifecycle.

Executes the provided function f with a resource managed via Using while handling the resource lifecycle.

This method takes a Try of resource type R and applies the function f to the successfully acquired resource if ry. If ry is a Failure, the failure is propagated.

Type parameters

A

the type of the result produced by the function f.

R

the type of the resource being managed.

Value parameters

f

a function that operates on the resource of type R and produces a result of type A.

ry

a Try[R] representing a resource to be used. If Success, the resource is passed to the function f.

Attributes

Returns

a Try[A] containing the result of applying f to the resource if ry is Success, or propagating the Failure if ry is Failure.

def tryIt[R : Releasable, A](ry: => Try[R])(f: R => Try[A]): Try[A]

This method is similar to apply(r), but it takes a Try[R] as its parameter. The definition of f is the same as in the other apply, however.

This method is similar to apply(r), but it takes a Try[R] as its parameter. The definition of f is the same as in the other apply, however.

TEST

Type parameters

A

the underlying type of the result.

R

the resource type.

Value parameters

f

a function of R => Try[A].

ry

a Try[R] which is passed into f and will be managed via Using.apply.

Attributes

Returns

a Try[A]