The iteratee
function in the Underscore library takes an argument and returns a function that can be used to transform a data set.
Here's an example of how to use the iteratee
function in Typescript:
index.ts566 chars20 lines
In this example, we first define an array of objects with the properties id
, name
, and age
. We then define an iterator function using Underscore's iteratee
function, which takes an input object and returns a boolean.
The iteratee
function is typecasted by using the generic type parameter <{ age: number }>
which will infer the shape of the object based on the fields which are used in the iteratee.
Finally, we use the iterator with Underscore's filter
function to return an array of all customers whose age
is less than 30.
gistlibby LogSnag