# Class JELArrayFunction<I,O>

java.lang.Object
uk.ac.starlink.ttools.jel.JELArrayFunction<I,O>

All Implemented Interfaces:
  `Function<I,O>`

public class JELArrayFunction<I,O> extends Object implements Function<I,O>
Provides an array->array function in which input elements are mapped to output elements by use of a given JEL expression.

Instances of this class are not threadsafe.

Since:
  23 Mar 2021
Author:
  Mark Taylor

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static class`
`JELArrayFunction.XResolver`
This public class is an implementation detail, not intended for external use.

## Constructor Summary

Constructors
Constructor
Description
`JELArrayFunction(String ivarName, String xvarName, String fexpr, Class<I> inClazz, Class<O> outClazz)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`O`
`apply(I inArray)`
Does exactly the same as `evaluate(I)`.
`O`
`evaluate(I inArray)`
Evaluates this expression.
`static <I> Object`
`evaluate(String ivarName, String xvarName, String fexpr, I inArray)`
Utility method to create and use an array function in one go.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface Function

`andThen, compose`

## Constructor Details

### JELArrayFunction

public JELArrayFunction(String ivarName, String xvarName, String fexpr, Class<I> inClazz, Class<O> outClazz) throws gnu.jel.CompilationException
Constructor.

Parameters:
  `ivarName` - name of the array index variable (0-based)
  `xvarName` - name of the array element variable (for instance "x")
  `fexpr` - text of expression giving the function value, in terms of `xvarname` (for instance "x+1")
  `inClazz` - type of input array; must be an array type of primitive or object elements
  `outClazz` - type of output array; if not known, Object.class may be given, and the output type will be determined from the expression
Throws:
  `gnu.jel.CompilationException`

## Method Details

### evaluate

public O evaluate(I inArray)
Evaluates this expression. Elements for which the evaluation failed are given some type-dependent default value, such as NaN, null, or zero.

Parameters:
  `inArray` - input array
Returns:
  outArray output array, same length as input

### apply

public O apply(I inArray)
Does exactly the same as `evaluate(I)`.

Specified by:
  `apply` in interface `Function<I,O>`

### evaluate

public static <I> Object evaluate(String ivarName, String xvarName, String fexpr, I inArray) throws gnu.jel.CompilationException
Utility method to create and use an array function in one go.

Parameters:
  `ivarName` - name of the array index variable (for instance "i")
  `xvarName` - name of the array element variable (for instance "x")
  `fexpr` - text of expression giving the function value, in terms of `xvarname` (for instance "x+1")
  `inArray` - input array
Returns:
  output array, same length as input
Throws:
  `gnu.jel.CompilationException`