A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://scala-lang.org/api/3.x/scala/util/control/TailCalls$.html below:

TailCalls

scala.util.control.TailCalls

Methods exported by this object implement tail calls via trampolining.

Tail calling methods must either return their result using done or call the next method using tailcall. Both return an instance of TailRec. The result of evaluating a tailcalling function can be retrieved from a TailRec value using method result.

Implemented as described in "Stackless Scala with Free Monads" https://blog.higher-order.com/assets/trampolines.pdf

Here's a usage example:

import scala.util.control.TailCalls._

def isEven(xs: List[Int]): TailRec[Boolean] =
  if (xs.isEmpty) done(true) else tailcall(isOdd(xs.tail))

def isOdd(xs: List[Int]): TailRec[Boolean] =
 if (xs.isEmpty) done(false) else tailcall(isEven(xs.tail))

isEven((1 to 100000).toList).result

def fib(n: Int): TailRec[Int] =
  if (n < 2) done(n) else for {
    x <- tailcall(fib(n - 1))
    y <- tailcall(fib(n - 2))
  } yield x + y

fib(40).result
Attributes
Source
TailCalls.scala
Graph
Supertypes
Self type
Members list

This class represents a tailcalling computation.

This class represents a tailcalling computation.

Attributes
Source
TailCalls.scala
Supertypes

Return the final result from a tailcalling computation.

Return the final result from a tailcalling computation.

Value parameters
`result`

the result value

Attributes
Returns

a TailRec object representing a computation which immediately returns result

Source
TailCalls.scala

Perform a tailcall.

Perform a tailcall.

Value parameters
rest

the expression to be evaluated in the tailcall

Attributes
Returns

a TailRec object representing the expression rest

Source
TailCalls.scala

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4