|
Scala example source code file (TraverseTestJVM.scala)
The TraverseTestJVM.scala Scala example source codepackage 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]) = Traverse[List].traverseImpl(fa)(f) } 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 |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
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.