de.larsgrefer.sass.embedded.functions.FunctionHostFunction Maven / Gradle / Ivy
package de.larsgrefer.sass.embedded.functions;
import com.sass_lang.embedded_protocol.Value;
import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
/**
* @author Lars Grefer
*/
class FunctionHostFunction extends HostFunction {
private static final List args = Collections.singletonList(
new Argument("arg0", null)
);
private final Function lambda;
private final Class argType;
protected FunctionHostFunction(String name, Class argType, Function lambda) {
super(name, args);
this.lambda = lambda;
this.argType = argType;
}
@Override
@Nonnull
public Value invoke(List arguments) {
if (arguments.size() != 1) {
throw new IllegalArgumentException("Invalid argument count: Expected 1 instead of " + arguments.size());
}
T arg0 = ConversionService.toJavaValue(arguments.get(0), argType, argType);
Object call = lambda.apply(arg0);
return ConversionService.toSassValue(call);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy