Utils

io.github.scala_tessella.dcel.Utils
object Utils

Attributes

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

Members list

Extensions

Extensions

extension [E, A](eitherList: List[Either[E, A]])
def sequence: Either[E, List[A]]

Transforms a list of Either values into a single Either containing a list of successful values or the first encountered error.

Transforms a list of Either values into a single Either containing a list of successful values or the first encountered error.

Attributes

Returns

an Either containing:

  • Right(List[A]) if all elements in the list are Right
  • Left(E) if at least one element in the list is Left, with the first error encountered.
extension [A](maybeA: Option[A])
def traverse[E, B](f: A => Either[E, B]): Either[E, Option[B]]

Applies a function to the value inside an Option, propagating errors using Either.

Applies a function to the value inside an Option, propagating errors using Either.

Value parameters

f

the function to be applied to the value inside the Option, producing an Either result.

Attributes

Returns

either an error of type E or an Option containing the transformed value of type B.

extension [A](seq: Seq[A])
def associate[T](f: A => T): Map[A, T]

Convert to a Map where key is the element and value is a function applied to it

Convert to a Map where key is the element and value is a function applied to it

Value parameters

f

the function transforming each element

Attributes

Returns

a Map mapping each element to its transformation.

Example
List(1, 2).associate(_ + 1) // Map(1 -> 2, 2 -> 3)
def associateValues[T](f: A => T): Map[T, A]

Creates a Map where each key is the result of applying a function to the elements of the sequence and the corresponding value is the original element.

Creates a Map where each key is the result of applying a function to the elements of the sequence and the corresponding value is the original element.

Value parameters

f

the function used to transform each element to a key in the resulting Map.

Attributes

Returns

a Map where keys are the transformed elements and values are the original elements.