Recursion

com.phasmidsoftware.lascala.Recursion
object Recursion

Created by scalaprof on 11/9/16.

Attributes

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

Members list

Value members

Concrete methods

final def countRecurse[T, S, R, C : Counter](f: (C, T) => S, g: (R, S) => R, h: (Seq[T], T) => Seq[T], q: R => Boolean = ...)(ts: Seq[T], c: C, r: R): R

Generic tail-recursive method with counting. Typically, this is used to traverse through a tree, starting at the root of the tree.

Generic tail-recursive method with counting. Typically, this is used to traverse through a tree, starting at the root of the tree.

Type parameters

C

The type of the counter -- context-bound to Counter

R

the result type.

S

the return type of f, typically an Option[X] where X is something that can be combined with an R.

T

the underlying type of the work list.

Value parameters

c

a counter which will be incremented on each recursive call to countRecurse

f

the map function which takes a P and T and produces an S.

g

the reduce function which accumulates the result (the accumulator is passed as its first parameter and an S value is passed as the second).

h

the function which builds the T list from the existing T list and the given T. It is essential that the given T does not go back, as is, into the list!

q

the quick return function which, if q(r) yields true, the method immediately returns r. Defaults to always false.

r

the current value of the result, i.e. the "accumulator".

ts

a list of Ts to be worked on.

Attributes

Returns

a value of R.

final def genericCountRecurse[T, S, R, C : Counter](f: (C, T) => S, g: (R, S) => R, h: (Seq[T], T) => Seq[T], y: C => C, q: R => Boolean = ...)(ts: Seq[T], c: C, r: R): R

Generic tail-recursive method with counting. Typically, this is used to traverse through a tree, starting at the root of the tree.

Generic tail-recursive method with counting. Typically, this is used to traverse through a tree, starting at the root of the tree.

CONSIDER reformulating the quick-return function to take an S as its input, rather than an R. That would, however, not be trivial.

Type parameters

C

The type of the counter -- context-bound to Counter

R

the result type.

S

the return type of f, typically an Option[X] where X is something that can be combined with an R.

T

the underlying type of the work list.

Value parameters

c

a counter which will be incremented on each recursive call to countRecurse

f

the map function which takes a C and T and produces an S.

g

the reduce function which accumulates the result (the accumulator is passed as its first parameter and an S value is passed as the second).

h

the function which builds the T list from the existing T list and the given T. It is essential that the given T does not go back, as is, into the list!

q

the quick return function which, if q(r) yields true, the method immediately returns r. Defaults to always false.

r

the current value of the result, i.e. the "accumulator".

ts

a sequence of Ts to be worked on.

y

the function which yields the next P from a P

Attributes

Returns

a value of R.

final def genericRecurse[R, T](f: (R, T) => R, g: (Seq[T], T) => Seq[T], q: R => Boolean = ...)(r: R, ts: Seq[T]): R
final def recurse[T, S, R](f: T => S, g: (R, S) => R, h: (Seq[T], T) => Seq[T], q: R => Boolean = ...)(ts: Seq[T], r: R): R

Generic tail-recursive method (implementation actually invokes the tail-recursive countRecurse). Typically, this is used to traverse through a tree, starting at the root of the tree.

Generic tail-recursive method (implementation actually invokes the tail-recursive countRecurse). Typically, this is used to traverse through a tree, starting at the root of the tree.

Type parameters

R

the result type.

S

the return type of f, typically an Option[X] where X is something that can be combined with an R.

T

the underlying type of the work list.

Value parameters

f

the map function which takes a P and T and produces an S.

g

the reduce function which accumulates the result (the accumulator is passed as its first parameter and an S value is passed as the second).

h

the function which builds the T list from the existing T list and the given T. It is essential that the given T does not go back, as is, into the list!

q

the quick return function which, if q(r) yields true, the method immediately returns r. Defaults to always false.

r

the current value of the result, i.e. the "accumulator".

ts

a list of Ts to be worked on.

Attributes

Returns

a value of R.