public class LeoGenerator extends LeoFunction
LeoGenerator
is an object that behaves like a function, but
is "resumeable" from a yield statement. That is, after successive invocations
it will pick up executing the function after the yield statement.
Example:
var talk = gen() { var i = 0 yield "Hello: " + i i += 1 yield "World: " + i } println( talk() ) // prints Hello: 0 println( talk() ) // prints World: 1 println( talk() ) // prints null, the function is done computing
LeoObject.LeoType
env, runtime
NOOUTERS, outers
Constructor and Description |
---|
LeoGenerator(Leola runtime,
LeoObject env,
Bytecode bytecode) |
Modifier and Type | Method and Description |
---|---|
LeoObject |
clone() |
LeoArray |
filter(LeoObject function)
Returns a sequence consisting of those items from the generator for which function(item) is true
|
LeoObject |
foreach(LeoObject function)
Iterates through the array, invoking the supplied
function object for each element
|
LeoObject[] |
getLocals() |
boolean |
isGenerator() |
LeoArray |
map(LeoObject function)
Applies a function to each generator iteration.
|
static LeoGenerator |
read(Leola runtime,
LeoObject env,
DataInput in)
|
LeoObject |
reduce(LeoObject function)
Reduces all of the elements in this generator into one value.
|
void |
write(DataOutput out)
Writes this object out
|
$add, $eq, $gt, $lt, call, call, call, call, call, call, call, getBytecode, getNumberOfArgs, getValue, hasVarargs, isFunction
getOuters, isOuter
$add, $add, $add, $band, $band, $band, $band, $bnot, $bor, $bor, $bor, $bor, $bsl, $bsl, $bsl, $bsl, $bsr, $bsr, $bsr, $bsr, $div, $div, $div, $div, $eq, $eq, $eq, $eq, $gt, $gt, $gt, $gte, $gte, $gte, $gte, $index, $index, $index, $index, $lt, $lt, $lt, $lte, $lte, $lte, $lte, $mod, $mod, $mod, $mod, $mul, $mul, $mul, $mul, $neg, $neq, $neq, $neq, $neq, $req, $sindex, $sub, $sub, $sub, $sub, $xor, $xor, $xor, $xor, as, as, asByte, asChar, asDouble, asFloat, asInt, asLong, asShort, compareTo, equals, getNativeMember, getNativeMethod, getNativeMethod, getObject, getObject, getScope, getType, getValue, hasNativeMethod, hasNativeMethod, hasObject, hasObject, isArray, isAssignable, isBoolean, isClass, isError, isMap, isNamespace, isNativeClass, isNativeFunction, isNull, isNumber, isOfType, isOfType, isOfType, isOfType, isScopedObject, isString, isTrue, isTrue, read, removeInterfaceMethods, rethrow, setObject, setObject, throwAttributeAccessError, throwAttributeError, throwAttributeError, throwClassNotFoundError, throwDivideByZeroError, throwIfError, throwMethodError, throwNativeMethodError, throwNotImplementedError, toJavaObject, toLeoString, toString, valueOf, xcall, xcall, xcall, xcall, xcall, xcall, xcall, xgetObject, xgetObject
public LeoObject[] getLocals()
public boolean isGenerator()
isGenerator
in class LeoObject
public LeoArray filter(LeoObject function)
var count = def(to) { return gen() { var i = 0 while i < to { yield i i += 1 } } } filter(count(5), def(e) return e%2==0) .foreach(println) // prints: // 0 // 2 // 4
function
- LeoArray
public LeoObject foreach(LeoObject function)
var count = def(to) { return gen() { var i = 0 while i < to { yield i i += 1 } } } foreach(count(5), println) // prints: // 0 // 1 // 2 // 3 // 4
function
- LeoObject
returned from the supplied function if returned true
public LeoArray map(LeoObject function)
var count = def(to) { return gen() { var i = 0 while i < to { yield i i += 1 } } } map(count(5), def(e) return e + 10) .foreach(println) // prints: // 10 // 11 // 12 // 13 // 14
function
- LeoArray
of resultspublic LeoObject reduce(LeoObject function)
var count = def(to) { return gen() { var i = 0 while i < to { yield i i += 1 } } } var sum = reduce(count(5), def(p,n) return p+n) println(sum) // 10
function
- public LeoObject clone()
clone
in class LeoFunction
public void write(DataOutput out) throws IOException
LeoObject
write
in class LeoFunction
IOException
public static LeoGenerator read(Leola runtime, LeoObject env, DataInput in) throws IOException
in
- LeoObject
IOException
Copyright © 2010–2015. All rights reserved.