o

catslib

TraverseSection

object TraverseSection extends AnyFlatSpec with Matchers with Section

In functional programming it is very common to encode "effects" as data types - common effects include Option for possibly missing values, Either and Validated for possible errors, and Future for asynchronous computations.

These effects tend to show up in functions working on a single piece of data - for instance parsing a single String into an Int, validating a login, or asynchronously fetching website information for a user.

import scala.concurrent.Future

def parseInt(s: String): Option[Int] = ???

trait SecurityError
trait Credentials

def validateLogin(cred: Credentials): Either[SecurityError, Unit] = ???

trait Profile
trait User

def userInfo(user: User): Future[Profile] = ???

Each function asks only for the data it actually needs; in the case of userInfo, a single User. We certainly could write one that takes a List[User] and fetch the profile for all of them, though it would be a bit strange since fetching a single user would require us to either wrap it in a List, or write a separate function that takes in a single user anyways. More fundamentally, functional programming is about building lots of small, independent pieces and composing them to make larger and larger pieces - does this hold true in this case?

Given just User => Future[Profile], what should we do if we want to fetch profiles for a List[User]? We could try familiar combinators like map.

def profilesFor(users: List[User]): List[Future[Profile]] = users.map(userInfo)

Note the return type List[Future[Profile]]. This makes sense given the type signatures, but seems unwieldy. We now have a list of asynchronous values, and to work with those values we must then use the combinators on Future for every single one. It would be nicer instead if we could get the aggregate result in a single Future, say a Future[List[Profile]].

As it turns out, the Future companion object has a traverse method on it. However, that method is specialized to standard library collections and Futures - there exists a much more generalized form that would allow us to parse a List[String] or validate credentials for a List[User].

Enter Traverse.

The type class

At center stage of Traverse is the traverse method.

trait Traverse[F[_]] {
def traverse[G[_] : Applicative, A, B](fa: F[A])(f: A => G[B]): G[F[B]]
}

In our above example, F is List, and G is Option, Either, or Future. For the profile example, traverse says given a List[User] and a function User => Future[Profile], it can give you a Future[List[Profile]].

Abstracting away the G (still imagining F to be List), traverse says given a collection of data, and a function that takes a piece of data and returns an effectful value, it will traverse the collection, applying the function and aggregating the effectful values (in a List) as it goes.

In the most general form, F[_] is some sort of context which may contain a value (or several). While List tends to be among the most general cases, there also exist Traverse instances for Option, Either, and Validated (among others).

Linear Supertypes
Section, Matchers, Explicitly, MatcherWords, Tolerance, AnyFlatSpec, AnyFlatSpecLike, Documenting, Alerting, Notifying, Informing, CanVerb, MustVerb, ShouldVerb, TestRegistration, TestSuite, Suite, Serializable, Assertions, TripleEquals, TripleEqualsSupport, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. TraverseSection
  2. Section
  3. Matchers
  4. Explicitly
  5. MatcherWords
  6. Tolerance
  7. AnyFlatSpec
  8. AnyFlatSpecLike
  9. Documenting
  10. Alerting
  11. Notifying
  12. Informing
  13. CanVerb
  14. MustVerb
  15. ShouldVerb
  16. TestRegistration
  17. TestSuite
  18. Suite
  19. Serializable
  20. Assertions
  21. TripleEquals
  22. TripleEqualsSupport
  23. AnyRef
  24. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. final class AWord extends AnyRef
    Definition Classes
    Matchers
  2. final class AnWord extends AnyRef
    Definition Classes
    Matchers
  3. sealed class AnyShouldWrapper[T] extends AnyRef
    Definition Classes
    Matchers
  4. final class BehaviorWord extends AnyRef
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  5. class CheckingEqualizer[L] extends AnyRef
    Definition Classes
    TripleEqualsSupport
  6. sealed class Collected extends Serializable
    Attributes
    protected
    Definition Classes
    Matchers
  7. class DecidedByEquality[A] extends Equality[A]
    Definition Classes
    Explicitly
  8. class DecidedWord extends AnyRef
    Definition Classes
    Explicitly
  9. class DeterminedByEquivalence[T] extends Equivalence[T]
    Definition Classes
    Explicitly
  10. class DeterminedWord extends AnyRef
    Definition Classes
    Explicitly
  11. class Equalizer[L] extends AnyRef
    Definition Classes
    TripleEqualsSupport
  12. final class HavePropertyMatcherGenerator extends AnyRef
    Definition Classes
    Matchers
  13. final class IgnoreVerbString extends AnyRef
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  14. final class IgnoreVerbStringTaggedAs extends AnyRef
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  15. final class IgnoreWord extends AnyRef
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  16. final class InAndIgnoreMethods extends AnyRef
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  17. final class InAndIgnoreMethodsAfterTaggedAs extends AnyRef
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  18. final class ItVerbString extends AnyRef
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  19. final class ItVerbStringTaggedAs extends AnyRef
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  20. final class ItWord extends AnyRef
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  21. final class KeyWord extends AnyRef
    Definition Classes
    Matchers
  22. trait NoArgTest extends () => Outcome with TestData
    Attributes
    protected
    Definition Classes
    TestSuite
  23. final class PlusOrMinusWrapper[T] extends AnyRef
    Definition Classes
    Tolerance
  24. final class RegexWord extends AnyRef
    Definition Classes
    Matchers
  25. final class RegexWrapper extends AnyRef
    Definition Classes
    Matchers
  26. class ResultOfBeWordForAny[T] extends AnyRef
    Definition Classes
    Matchers
  27. sealed class ResultOfBeWordForCollectedAny[T] extends AnyRef
    Definition Classes
    Matchers
  28. final class ResultOfBeWordForCollectedArray[T] extends ResultOfBeWordForCollectedAny[Array[T]]
    Definition Classes
    Matchers
  29. final class ResultOfCollectedAny[T] extends AnyRef
    Definition Classes
    Matchers
  30. final class ResultOfContainWordForCollectedAny[T] extends AnyRef
    Definition Classes
    Matchers
  31. final class ResultOfEndWithWordForCollectedString extends AnyRef
    Definition Classes
    Matchers
  32. final class ResultOfEndWithWordForString extends AnyRef
    Definition Classes
    Matchers
  33. final class ResultOfFullyMatchWordForCollectedString extends AnyRef
    Definition Classes
    Matchers
  34. final class ResultOfFullyMatchWordForString extends AnyRef
    Definition Classes
    Matchers
  35. final class ResultOfHaveWordForCollectedExtent[A] extends AnyRef
    Definition Classes
    Matchers
  36. final class ResultOfHaveWordForExtent[A] extends AnyRef
    Definition Classes
    Matchers
  37. final class ResultOfIncludeWordForCollectedString extends AnyRef
    Definition Classes
    Matchers
  38. final class ResultOfIncludeWordForString extends AnyRef
    Definition Classes
    Matchers
  39. final class ResultOfNotWordForCollectedAny[T] extends AnyRef
    Definition Classes
    Matchers
  40. final class ResultOfStartWithWordForCollectedString extends AnyRef
    Definition Classes
    Matchers
  41. final class ResultOfStartWithWordForString extends AnyRef
    Definition Classes
    Matchers
  42. trait StringCanWrapperForVerb extends AnyRef
    Definition Classes
    CanVerb
  43. trait StringMustWrapperForVerb extends AnyRef
    Definition Classes
    MustVerb
  44. final class StringShouldWrapper extends AnyShouldWrapper[String] with org.scalatest.matchers.should.Matchers.StringShouldWrapperForVerb
    Definition Classes
    Matchers
  45. trait StringShouldWrapperForVerb extends AnyRef
    Definition Classes
    ShouldVerb
  46. class TheAfterWord extends AnyRef
    Definition Classes
    Explicitly
  47. final class TheSameInstanceAsPhrase extends AnyRef
    Definition Classes
    Matchers
  48. final class TheyVerbString extends AnyRef
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  49. final class TheyVerbStringTaggedAs extends AnyRef
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  50. final class TheyWord extends AnyRef
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  51. final class ValueWord extends AnyRef
    Definition Classes
    Matchers

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. def !==[T](right: Spread[T]): TripleEqualsInvocationOnSpread[T]
    Definition Classes
    TripleEqualsSupport
  3. def !==(right: Null): TripleEqualsInvocation[Null]
    Definition Classes
    TripleEqualsSupport
  4. def !==[T](right: T): TripleEqualsInvocation[T]
    Definition Classes
    TripleEqualsSupport
  5. final def ##: Int
    Definition Classes
    AnyRef → Any
  6. def <[T](right: T)(implicit arg0: Ordering[T]): ResultOfLessThanComparison[T]
    Definition Classes
    Matchers
  7. def <=[T](right: T)(implicit arg0: Ordering[T]): ResultOfLessThanOrEqualToComparison[T]
    Definition Classes
    Matchers
  8. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  9. def ===[T](right: Spread[T]): TripleEqualsInvocationOnSpread[T]
    Definition Classes
    TripleEqualsSupport
  10. def ===(right: Null): TripleEqualsInvocation[Null]
    Definition Classes
    TripleEqualsSupport
  11. def ===[T](right: T): TripleEqualsInvocation[T]
    Definition Classes
    TripleEqualsSupport
  12. def >[T](right: T)(implicit arg0: Ordering[T]): ResultOfGreaterThanComparison[T]
    Definition Classes
    Matchers
  13. def >=[T](right: T)(implicit arg0: Ordering[T]): ResultOfGreaterThanOrEqualToComparison[T]
    Definition Classes
    Matchers
  14. def a[T](implicit arg0: ClassTag[T]): ResultOfATypeInvocation[T]
    Definition Classes
    Matchers
  15. val a: AWord
    Definition Classes
    Matchers
  16. val after: TheAfterWord
    Definition Classes
    Explicitly
  17. def alert: Alerter
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike → Alerting
  18. def all(xs: String)(implicit collecting: Collecting[Char, String], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[Char]
    Definition Classes
    Matchers
  19. def all[K, V, JMAP[k, v] <: Map[k, v]](xs: JMAP[K, V])(implicit collecting: Collecting[Entry[K, V], JMAP[K, V]], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[Entry[K, V]]
    Definition Classes
    Matchers
  20. def all[K, V, MAP[k, v] <: GenMap[k, v]](xs: MAP[K, V])(implicit collecting: Collecting[(K, V), GenTraversable[(K, V)]], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[(K, V)]
    Definition Classes
    Matchers
  21. def all[E, C[_]](xs: C[E])(implicit collecting: Collecting[E, C[E]], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[E]
    Definition Classes
    Matchers
  22. def allElementsOf[R](elements: GenTraversable[R]): ResultOfAllElementsOfApplication
    Definition Classes
    Matchers
  23. def allOf(firstEle: Any, secondEle: Any, remainingEles: Any*)(implicit pos: Position): ResultOfAllOfApplication
    Definition Classes
    Matchers
  24. def an[T](implicit arg0: ClassTag[T]): ResultOfAnTypeInvocation[T]
    Definition Classes
    Matchers
  25. val an: AnWord
    Definition Classes
    Matchers
  26. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  27. macro def assert(condition: Boolean, clue: Any)(implicit prettifier: Prettifier, pos: Position): Assertion
    Definition Classes
    Assertions
  28. macro def assert(condition: Boolean)(implicit prettifier: Prettifier, pos: Position): Assertion
    Definition Classes
    Assertions
  29. macro def assertCompiles(code: String)(implicit pos: Position): Assertion
    Definition Classes
    Assertions
  30. macro def assertDoesNotCompile(code: String)(implicit pos: Position): Assertion
    Definition Classes
    Assertions
  31. def assertResult(expected: Any)(actual: Any)(implicit prettifier: Prettifier, pos: Position): Assertion
    Definition Classes
    Assertions
  32. def assertResult(expected: Any, clue: Any)(actual: Any)(implicit prettifier: Prettifier, pos: Position): Assertion
    Definition Classes
    Assertions
  33. def assertThrows[T <: AnyRef](f: => Any)(implicit classTag: ClassTag[T], pos: Position): Assertion
    Definition Classes
    Assertions
  34. macro def assertTypeError(code: String)(implicit pos: Position): Assertion
    Definition Classes
    Assertions
  35. macro def assume(condition: Boolean, clue: Any)(implicit prettifier: Prettifier, pos: Position): Assertion
    Definition Classes
    Assertions
  36. macro def assume(condition: Boolean)(implicit prettifier: Prettifier, pos: Position): Assertion
    Definition Classes
    Assertions
  37. def atLeast(num: Int, xs: String)(implicit collecting: Collecting[Char, String], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[Char]
    Definition Classes
    Matchers
  38. def atLeast[K, V, JMAP[k, v] <: Map[k, v]](num: Int, xs: JMAP[K, V])(implicit collecting: Collecting[Entry[K, V], JMAP[K, V]], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[Entry[K, V]]
    Definition Classes
    Matchers
  39. def atLeast[K, V, MAP[k, v] <: GenMap[k, v]](num: Int, xs: MAP[K, V])(implicit collecting: Collecting[(K, V), GenTraversable[(K, V)]], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[(K, V)]
    Definition Classes
    Matchers
  40. def atLeast[E, C[_]](num: Int, xs: C[E])(implicit collecting: Collecting[E, C[E]], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[E]
    Definition Classes
    Matchers
  41. def atLeastOneElementOf(elements: GenTraversable[Any]): ResultOfAtLeastOneElementOfApplication
    Definition Classes
    Matchers
  42. def atLeastOneOf(firstEle: Any, secondEle: Any, remainingEles: Any*)(implicit pos: Position): ResultOfAtLeastOneOfApplication
    Definition Classes
    Matchers
  43. def atMost(num: Int, xs: String)(implicit collecting: Collecting[Char, String], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[Char]
    Definition Classes
    Matchers
  44. def atMost[K, V, JMAP[k, v] <: Map[k, v]](num: Int, xs: JMAP[K, V])(implicit collecting: Collecting[Entry[K, V], JMAP[K, V]], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[Entry[K, V]]
    Definition Classes
    Matchers
  45. def atMost[K, V, MAP[k, v] <: GenMap[k, v]](num: Int, xs: MAP[K, V])(implicit collecting: Collecting[(K, V), GenTraversable[(K, V)]], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[(K, V)]
    Definition Classes
    Matchers
  46. def atMost[E, C[_]](num: Int, xs: C[E])(implicit collecting: Collecting[E, C[E]], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[E]
    Definition Classes
    Matchers
  47. def atMostOneElementOf[R](elements: GenTraversable[R]): ResultOfAtMostOneElementOfApplication
    Definition Classes
    Matchers
  48. def atMostOneOf(firstEle: Any, secondEle: Any, remainingEles: Any*)(implicit pos: Position): ResultOfAtMostOneOfApplication
    Definition Classes
    Matchers
  49. val be: BeWord
    Definition Classes
    MatcherWords
  50. val behave: BehaveWord
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  51. val behavior: BehaviorWord
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  52. def between(from: Int, upTo: Int, xs: String)(implicit collecting: Collecting[Char, String], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[Char]
    Definition Classes
    Matchers
  53. def between[K, V, JMAP[k, v] <: Map[k, v]](from: Int, upTo: Int, xs: JMAP[K, V])(implicit collecting: Collecting[Entry[K, V], JMAP[K, V]], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[Entry[K, V]]
    Definition Classes
    Matchers
  54. def between[E, C[_]](from: Int, upTo: Int, xs: C[E])(implicit collecting: Collecting[E, C[E]], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[E]
    Definition Classes
    Matchers
  55. def cancel(cause: Throwable)(implicit pos: Position): Nothing
    Definition Classes
    Assertions
  56. def cancel(message: String, cause: Throwable)(implicit pos: Position): Nothing
    Definition Classes
    Assertions
  57. def cancel(message: String)(implicit pos: Position): Nothing
    Definition Classes
    Assertions
  58. def cancel()(implicit pos: Position): Nothing
    Definition Classes
    Assertions
  59. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  60. val compile: CompileWord
    Definition Classes
    MatcherWords
  61. val contain: ContainWord
    Definition Classes
    MatcherWords
  62. def convertEquivalenceToAToBConstraint[A, B](equivalenceOfB: Equivalence[B])(implicit ev: <:<[A, B]): CanEqual[A, B]
    Definition Classes
    TripleEquals → TripleEqualsSupport
  63. def convertEquivalenceToBToAConstraint[A, B](equivalenceOfA: Equivalence[A])(implicit ev: <:<[B, A]): CanEqual[A, B]
    Definition Classes
    TripleEquals → TripleEqualsSupport
  64. implicit def convertNumericToPlusOrMinusWrapper[T](pivot: T)(implicit arg0: Numeric[T]): PlusOrMinusWrapper[T]
    Definition Classes
    Tolerance
  65. implicit def convertSymbolToHavePropertyMatcherGenerator(symbol: Symbol)(implicit prettifier: Prettifier, pos: Position): HavePropertyMatcherGenerator
    Definition Classes
    Matchers
  66. implicit def convertToAnyShouldWrapper[T](o: T)(implicit pos: Position, prettifier: Prettifier): AnyShouldWrapper[T]
    Definition Classes
    Matchers
  67. def convertToCheckingEqualizer[T](left: T): CheckingEqualizer[T]
    Definition Classes
    TripleEquals → TripleEqualsSupport
  68. implicit def convertToEqualizer[T](left: T): Equalizer[T]
    Definition Classes
    TripleEquals → TripleEqualsSupport
  69. implicit def convertToInAndIgnoreMethods(resultOfStringPassedToVerb: ResultOfStringPassedToVerb): InAndIgnoreMethods
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  70. implicit def convertToInAndIgnoreMethodsAfterTaggedAs(resultOfTaggedAsInvocation: ResultOfTaggedAsInvocation): InAndIgnoreMethodsAfterTaggedAs
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  71. implicit def convertToRegexWrapper(o: Regex): RegexWrapper
    Definition Classes
    Matchers
  72. implicit def convertToStringCanWrapper(o: String)(implicit position: Position): StringCanWrapperForVerb
    Definition Classes
    CanVerb
  73. implicit def convertToStringMustWrapperForVerb(o: String)(implicit position: Position): StringMustWrapperForVerb
    Definition Classes
    MustVerb
  74. implicit def convertToStringShouldWrapper(o: String)(implicit pos: Position, prettifier: Prettifier): StringShouldWrapper
    Definition Classes
    Matchers
  75. implicit def convertToStringShouldWrapperForVerb(o: String)(implicit position: Position): StringShouldWrapperForVerb
    Definition Classes
    ShouldVerb
  76. val decided: DecidedWord
    Definition Classes
    Explicitly
  77. def defaultEquality[A]: Equality[A]
    Definition Classes
    TripleEqualsSupport
  78. val defined: DefinedWord
    Definition Classes
    MatcherWords
  79. def definedAt[T](right: T): ResultOfDefinedAt[T]
    Definition Classes
    Matchers
  80. val determined: DeterminedWord
    Definition Classes
    Explicitly
  81. val empty: EmptyWord
    Definition Classes
    MatcherWords
  82. val endWith: EndWithWord
    Definition Classes
    MatcherWords
  83. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  84. def equal(o: Null): Matcher[AnyRef]
    Definition Classes
    Matchers
  85. def equal[T](spread: Spread[T]): Matcher[T]
    Definition Classes
    Matchers
  86. def equal(right: Any): MatcherFactory1[Any, Equality]
    Definition Classes
    MatcherWords
  87. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  88. def every(xs: String)(implicit collecting: Collecting[Char, String], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[Char]
    Definition Classes
    Matchers
  89. def every[K, V, JMAP[k, v] <: Map[k, v]](xs: JMAP[K, V])(implicit collecting: Collecting[Entry[K, V], JMAP[K, V]], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[Entry[K, V]]
    Definition Classes
    Matchers
  90. def every[K, V, MAP[k, v] <: Map[k, v]](xs: MAP[K, V])(implicit collecting: Collecting[(K, V), GenTraversable[(K, V)]], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[(K, V)]
    Definition Classes
    Matchers
  91. def every[E, C[_]](xs: C[E])(implicit collecting: Collecting[E, C[E]], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[E]
    Definition Classes
    Matchers
  92. def exactly(num: Int, xs: String)(implicit collecting: Collecting[Char, String], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[Char]
    Definition Classes
    Matchers
  93. def exactly[K, V, JMAP[k, v] <: Map[k, v]](num: Int, xs: JMAP[K, V])(implicit collecting: Collecting[Entry[K, V], JMAP[K, V]], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[Entry[K, V]]
    Definition Classes
    Matchers
  94. def exactly[K, V, MAP[k, v] <: GenMap[k, v]](num: Int, xs: MAP[K, V])(implicit collecting: Collecting[(K, V), GenTraversable[(K, V)]], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[(K, V)]
    Definition Classes
    Matchers
  95. def exactly[E, C[_]](num: Int, xs: C[E])(implicit collecting: Collecting[E, C[E]], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[E]
    Definition Classes
    Matchers
  96. final def execute(testName: String, configMap: ConfigMap, color: Boolean, durations: Boolean, shortstacks: Boolean, fullstacks: Boolean, stats: Boolean): Unit
    Definition Classes
    Suite
  97. val exist: ExistWord
    Definition Classes
    MatcherWords
  98. def expectedTestCount(filter: Filter): Int
    Definition Classes
    Suite
  99. def fail(cause: Throwable)(implicit pos: Position): Nothing
    Definition Classes
    Assertions
  100. def fail(message: String, cause: Throwable)(implicit pos: Position): Nothing
    Definition Classes
    Assertions
  101. def fail(message: String)(implicit pos: Position): Nothing
    Definition Classes
    Assertions
  102. def fail()(implicit pos: Position): Nothing
    Definition Classes
    Assertions
  103. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  104. val fullyMatch: FullyMatchWord
    Definition Classes
    MatcherWords
  105. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  106. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  107. val have: HaveWord
    Definition Classes
    MatcherWords
  108. val ignore: IgnoreWord
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  109. def inOrder(firstEle: Any, secondEle: Any, remainingEles: Any*)(implicit pos: Position): ResultOfInOrderApplication
    Definition Classes
    Matchers
  110. def inOrderElementsOf[R](elements: GenTraversable[R]): ResultOfInOrderElementsOfApplication
    Definition Classes
    Matchers
  111. def inOrderOnly[T](firstEle: Any, secondEle: Any, remainingEles: Any*)(implicit pos: Position): ResultOfInOrderOnlyApplication
    Definition Classes
    Matchers
  112. val include: IncludeWord
    Definition Classes
    MatcherWords
  113. def info: Informer
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike → Informing
  114. def intercept[T <: AnyRef](f: => Any)(implicit classTag: ClassTag[T], pos: Position): T
    Definition Classes
    Assertions
  115. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  116. val it: ItWord
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  117. val key: KeyWord
    Definition Classes
    Matchers
  118. val length: LengthWord
    Definition Classes
    MatcherWords
  119. def lowPriorityTypeCheckedConstraint[A, B](implicit equivalenceOfB: Equivalence[B], ev: <:<[A, B]): CanEqual[A, B]
    Definition Classes
    TripleEquals → TripleEqualsSupport
  120. def markup: Documenter
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike → Documenting
  121. val matchPattern: MatchPatternWord
    Definition Classes
    MatcherWords
  122. def message(expectedMessage: String): ResultOfMessageWordApplication
    Definition Classes
    Matchers
  123. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  124. def nestedSuites: IndexedSeq[Suite]
    Definition Classes
    Suite
  125. def no(xs: String)(implicit collecting: Collecting[Char, String], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[Char]
    Definition Classes
    Matchers
  126. def no[K, V, JMAP[k, v] <: Map[k, v]](xs: JMAP[K, V])(implicit collecting: Collecting[Entry[K, V], JMAP[K, V]], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[Entry[K, V]]
    Definition Classes
    Matchers
  127. def no[E, C[_]](xs: C[E])(implicit collecting: Collecting[E, C[E]], prettifier: Prettifier, pos: Position): ResultOfCollectedAny[E]
    Definition Classes
    Matchers
  128. def noElementsOf(elements: GenTraversable[Any]): ResultOfNoElementsOfApplication
    Definition Classes
    Matchers
  129. def noException(implicit pos: Position): NoExceptionWord
    Definition Classes
    MatcherWords
  130. def noneOf(firstEle: Any, secondEle: Any, remainingEles: Any*)(implicit pos: Position): ResultOfNoneOfApplication
    Definition Classes
    Matchers
  131. val not: NotWord
    Definition Classes
    MatcherWords
  132. def note: Notifier
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike → Notifying
  133. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  134. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  135. def of[T](implicit ev: ClassTag[T]): ResultOfOfTypeInvocation[T]
    Definition Classes
    Matchers
  136. def oneElementOf(elements: GenTraversable[Any]): ResultOfOneElementOfApplication
    Definition Classes
    Matchers
  137. def oneOf(firstEle: Any, secondEle: Any, remainingEles: Any*)(implicit pos: Position): ResultOfOneOfApplication
    Definition Classes
    Matchers
  138. def only(xs: Any*)(implicit pos: Position): ResultOfOnlyApplication
    Definition Classes
    Matchers
  139. def pending: Assertion with PendingStatement
    Definition Classes
    Assertions
  140. def pendingUntilFixed(f: => Unit)(implicit pos: Position): Assertion with PendingStatement
    Definition Classes
    Assertions
  141. val readable: ReadableWord
    Definition Classes
    MatcherWords
  142. val regex: RegexWord
    Definition Classes
    Matchers
  143. final def registerIgnoredTest(testText: String, testTags: Tag*)(testFun: => Any)(implicit pos: Position): Unit
    Definition Classes
    AnyFlatSpecLike → TestRegistration
  144. final def registerTest(testText: String, testTags: Tag*)(testFun: => Any)(implicit pos: Position): Unit
    Definition Classes
    AnyFlatSpecLike → TestRegistration
  145. def rerunner: Option[String]
    Definition Classes
    Suite
  146. def run(testName: Option[String], args: Args): Status
    Definition Classes
    AnyFlatSpecLike → Suite
  147. def runNestedSuites(args: Args): Status
    Attributes
    protected
    Definition Classes
    Suite
  148. def runTest(testName: String, args: Args): Status
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike → TestSuite → Suite
  149. def runTests(testName: Option[String], args: Args): Status
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike → Suite
  150. def sequencing(res0: Option[List[Int]], res1: Option[List[Int]]): Assertion

    Notice that in the Either case, should any string fail to parse the entire traversal is considered a failure.

    Notice that in the Either case, should any string fail to parse the entire traversal is considered a failure. Moreover, once it hits its first bad parse, it will not attempt to parse any others down the line (similar behavior would be found with using Option as the effect). Contrast this with Validated where even if one bad parse is hit, it will continue trying to parse the others, accumulating any and all errors as it goes. The behavior of traversal is closely tied with the Applicative behavior of the data type.

    Going back to our Future example, we can write an Applicative instance for Future that runs each Future concurrently. Then when we traverse a List[A] with an A => Future[B], we can imagine the traversal as a scatter-gather. Each A creates a concurrent computation that will produce a B (the scatter), and as the Futures complete they will be gathered back into a List.

    Playing with Reader

    Another interesting effect we can use is Reader. Recall that a Reader[E, A] is a type alias for Kleisli[Id, E, A] which is a wrapper around E => A.

    If we fix E to be some sort of environment or configuration, we can use the Reader applicative in our traverse.

    import cats.data.Reader
    
    trait Context
    trait Topic
    trait Result
    
    type Job[A] = Reader[Context, A]
    
    def processTopic(topic: Topic): Job[Result] = ???

    We can imagine we have a data pipeline that processes a bunch of data, each piece of data being categorized by a topic. Given a specific topic, we produce a Job that processes that topic. (Note that since a Job is just a Reader/Kleisli, one could write many small Jobs and compose them together into one Job that is used/returned by processTopic.)

    Corresponding to our bunches of data are bunches of topics, a List[Topic] if you will. Since Reader has an Applicative instance, we can traverse over this list with processTopic.

    def processTopics(topics: List[Topic]) =
    topics.traverse(processTopic)

    Note the nice return type - Job[List[Result]]. We now have one aggregate Job that when run, will go through each topic and run the topic-specific job, collecting results as it goes. We say "when run" because a Job is some function that requires a Context before producing the value we want.

    One example of a "context" can be found in the Spark project. In Spark, information needed to run a Spark job (where the master node is, memory allocated, etc.) resides in a SparkContext. Going back to the above example, we can see how one may define topic-specific Spark jobs (type Job[A] = Reader[SparkContext, A]) and then run several Spark jobs on a collection of topics via traverse. We then get back a Job[List[Result]], which is equivalent to SparkContext => List[Result]. When finally passed a SparkContext, we can run the job and get our results back.

    Moreover, the fact that our aggregate job is not tied to any specific SparkContext allows us to pass in a SparkContext pointing to a production cluster, or (using the exact same job) pass in a test SparkContext that just runs locally across threads. This makes testing our large job nice and easy.

    Finally, this encoding ensures that all the jobs for each topic run on the exact same cluster. At no point do we manually pass in or thread a SparkContext through - that is taken care for us by the (applicative) effect of Reader and therefore by traverse.

    Sequencing

    Sometimes you may find yourself with a collection of data, each of which is already in an effect, for instance a List[Option[A]]. To make this easier to work with, you want a Option[List[A]]. Given Option has an Applicative instance, we can traverse over the list with the identity function.

  151. implicit val shorthandSharedTestRegistrationFunction: StringVerbBehaveLikeInvocation
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  152. implicit val shorthandTestRegistrationFunction: StringVerbStringInvocation
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  153. val size: SizeWord
    Definition Classes
    MatcherWords
  154. val sorted: SortedWord
    Definition Classes
    MatcherWords
  155. val startWith: StartWithWord
    Definition Classes
    MatcherWords
  156. final val succeed: Assertion
    Definition Classes
    Assertions
  157. def suiteId: String
    Definition Classes
    Suite
  158. def suiteName: String
    Definition Classes
    Suite
  159. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  160. def tags: Map[String, Set[String]]
    Definition Classes
    AnyFlatSpecLike → Suite
  161. def testDataFor(testName: String, theConfigMap: ConfigMap): TestData
    Definition Classes
    AnyFlatSpecLike → Suite
  162. def testNames: Set[String]
    Definition Classes
    AnyFlatSpecLike → Suite
  163. def the[T](implicit arg0: ClassTag[T], pos: Position): ResultOfTheTypeInvocation[T]
    Definition Classes
    Matchers
  164. def theSameElementsAs(xs: GenTraversable[_]): ResultOfTheSameElementsAsApplication
    Definition Classes
    Matchers
  165. def theSameElementsInOrderAs(xs: GenTraversable[_]): ResultOfTheSameElementsInOrderAsApplication
    Definition Classes
    Matchers
  166. val theSameInstanceAs: TheSameInstanceAsPhrase
    Definition Classes
    Matchers
  167. val they: TheyWord
    Attributes
    protected
    Definition Classes
    AnyFlatSpecLike
  168. def thrownBy(fun: => Any): ResultOfThrownByApplication
    Definition Classes
    Matchers
  169. def toString(): String
    Definition Classes
    AnyFlatSpec → AnyRef → Any
  170. def traverseuFunction(res0: List[Int], res1: Boolean): Assertion

    The type signature of Traverse appears highly abstract, and indeed it is - what traverse does as it walks the F[A] depends on the effect of the function.

    Choose your effect

    The type signature of Traverse appears highly abstract, and indeed it is - what traverse does as it walks the F[A] depends on the effect of the function. Let's see some examples where F is taken to be List.

    import cats.Semigroup
    import cats.data.{NonEmptyList, OneAnd, Validated, ValidatedNel}
    import cats.implicits._
    
    def parseIntEither(s: String): Either[NumberFormatException, Int] =
    Either.catchOnly[NumberFormatException](s.toInt)
    
    def parseIntValidated(s: String): ValidatedNel[NumberFormatException, Int] =
    Validated.catchOnly[NumberFormatException](s.toInt).toValidatedNel

    We can now traverse structures that contain strings parsing them into integers and accumulating failures with Either.

  171. def traverseuValidated(res0: Boolean): Assertion

    We need proof that NonEmptyList[A] is a Semigroup for there to be an Applicative instance for ValidatedNel.

    We need proof that NonEmptyList[A] is a Semigroup for there to be an Applicative instance for ValidatedNel.

    implicit def nelSemigroup[A]: Semigroup[NonEmptyList[A]] =
      OneAnd.oneAndSemigroupK[List].algebra[A]

    Now that we've provided such evidence, we can use ValidatedNel as an applicative.

  172. def traversingForEffects(res0: Option[Unit], res1: Option[Unit]): Assertion

    Traverse provides a convenience method sequence that does exactly this.

    Traverse provides a convenience method sequence that does exactly this.

    List(Option(1), Option(2), Option(3)).sequence
    List(Option(1), None, Option(3)).sequence

    Traversing for effect

    Sometimes our effectful functions return a Unit value in cases where there is no interesting value to return (e.g. writing to some sort of store).

    trait Data
    def writeToStore(data: Data): Future[Unit] = ???

    If we traverse using this, we end up with a funny type.

    import cats.implicits._
    import scala.concurrent.ExecutionContext.Implicits.global
    
    def writeManyToStore(data: List[Data]) =
    data.traverse(writeToStore)

    We end up with a Future[List[Unit]]! A List[Unit] is not of any use to us, and communicates the same amount of information as a single Unit does.

    Traversing solely for the sake of the effect (ignoring any values that may be produced, Unit or otherwise) is common, so Foldable (superclass of Traverse) provides traverse_ and sequence_ methods that do the same thing as traverse and sequence but ignores any value produced along the way, returning Unit at the end.

  173. val typeCheck: TypeCheckWord
    Definition Classes
    MatcherWords
  174. def typeCheckedConstraint[A, B](implicit equivalenceOfA: Equivalence[A], ev: <:<[B, A]): CanEqual[A, B]
    Definition Classes
    TripleEquals → TripleEqualsSupport
  175. implicit def unconstrainedEquality[A, B](implicit equalityOfA: Equality[A]): CanEqual[A, B]
    Definition Classes
    TripleEquals → TripleEqualsSupport
  176. val value: ValueWord
    Definition Classes
    Matchers
  177. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  178. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  179. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  180. def withClue[T](clue: Any)(fun: => T): T
    Definition Classes
    Assertions
  181. def withFixture(test: NoArgTest): Outcome
    Attributes
    protected
    Definition Classes
    TestSuite
  182. val writable: WritableWord
    Definition Classes
    MatcherWords

Deprecated Value Members

  1. def conversionCheckedConstraint[A, B](implicit equivalenceOfA: Equivalence[A], cnv: (B) => A): CanEqual[A, B]
    Definition Classes
    TripleEquals → TripleEqualsSupport
    Annotations
    @deprecated
    Deprecated

    (Since version 3.1.0) The conversionCheckedConstraint method has been deprecated and will be removed in a future version of ScalaTest. It is no longer needed now that the deprecation period of ConversionCheckedTripleEquals has expired. It will not be replaced.

  2. def convertEquivalenceToAToBConversionConstraint[A, B](equivalenceOfB: Equivalence[B])(implicit ev: (A) => B): CanEqual[A, B]
    Definition Classes
    TripleEquals → TripleEqualsSupport
    Annotations
    @deprecated
    Deprecated

    (Since version 3.1.0) The convertEquivalenceToAToBConversionConstraint method has been deprecated and will be removed in a future version of ScalaTest. It is no longer needed now that the deprecation period of ConversionCheckedTripleEquals has expired. It will not be replaced.

  3. def convertEquivalenceToBToAConversionConstraint[A, B](equivalenceOfA: Equivalence[A])(implicit ev: (B) => A): CanEqual[A, B]
    Definition Classes
    TripleEquals → TripleEqualsSupport
    Annotations
    @deprecated
    Deprecated

    (Since version 3.1.0) The convertEquivalenceToBToAConversionConstraint method has been deprecated and will be removed in a future version of ScalaTest. It is no longer needed now that the deprecation period of ConversionCheckedTripleEquals has expired. It will not be replaced.

  4. def lowPriorityConversionCheckedConstraint[A, B](implicit equivalenceOfB: Equivalence[B], cnv: (A) => B): CanEqual[A, B]
    Definition Classes
    TripleEquals → TripleEqualsSupport
    Annotations
    @deprecated
    Deprecated

    (Since version 3.1.0) The lowPriorityConversionCheckedConstraint method has been deprecated and will be removed in a future version of ScalaTest. It is no longer needed now that the deprecation period of ConversionCheckedTripleEquals has expired. It will not be replaced.

  5. final val styleName: String
    Definition Classes
    AnyFlatSpecLike → Suite
    Annotations
    @deprecated
    Deprecated

    (Since version 3.1.0) The styleName lifecycle method has been deprecated and will be removed in a future version of ScalaTest with no replacement.

Inherited from Section

Inherited from Matchers

Inherited from Explicitly

Inherited from MatcherWords

Inherited from Tolerance

Inherited from AnyFlatSpec

Inherited from AnyFlatSpecLike

Inherited from Documenting

Inherited from Alerting

Inherited from Notifying

Inherited from Informing

Inherited from CanVerb

Inherited from MustVerb

Inherited from ShouldVerb

Inherited from TestRegistration

Inherited from TestSuite

Inherited from Suite

Inherited from Serializable

Inherited from Assertions

Inherited from TripleEquals

Inherited from TripleEqualsSupport

Inherited from AnyRef

Inherited from Any

Ungrouped