| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (TraverseTestJVM.scala)

This example Scala source code file (TraverseTestJVM.scala) is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Scala by Example" TM.

Learn more about this Scala project at its project page.

Java - Scala tags/keywords

applicative, int, list, speclite, state, statet, traversetestjvm

The TraverseTestJVM.scala Scala example source code

package scalaz

import scalaz.State._
import std.AllInstances._
import syntax.traverse._

object TraverseTestJVM extends SpecLite {

  "list" should {
    "sequenceS, traverseS, traversalS does not blow stack" in {
      val N = 100000
      val F = new Traverse[List]{
        def traverseImpl[G[_]: Applicative, A, B](fa: List[A])(f: A => G[B]) =
      val s = List.fill(N)(modify((_: Int) + 1))
      F.sequenceS(s).exec(0) must_=== N
      F.traverseS(s)(x => x).exec(0) must_=== N
      F.traversalS[Int].run(s)(x => x).exec(0) must_=== N

  "combos" should {
    "traverse large stream over trampolined StateT including IO" in {
      // Example usage from Eric Torreborre
      import scalaz.effect._

      val as = Stream.range(0, 100000)
      val state: State[Int, IO[Stream[Int]]] = as.traverseSTrampoline[IO, Int, Int](a => for {
        s <- State.get[Int]
        _ <- State.put(a)
      } yield IO(a - s))
      state.eval(0).unsafePerformIO().take(3) must_===(Stream(0, 1, 1))

Other Scala examples (source code examples)

Here is a short list of links related to this Scala TraverseTestJVM.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.