Emulate underscore.js - agate 1.9.0 documentation

Hide navigation sidebar
Hide table of contents sidebar
Back to top
Toggle table of contents sidebar

# Emulate underscore.js

## filter

agate’s `Table.where()` functions exactly like Underscore’s `filter`.

    new_table = table.where(lambda row: row['state'] == 'Texas')

## reject

To simulate Underscore’s `reject`, simply negate the return value of the function you pass into agate’s `Table.where()`.

    new_table = table.where(lambda row: not (row['state'] == 'Texas'))

## find

agate’s `Table.find()` works exactly like Underscore’s `find`.

    row = table.find(lambda row: row['state'].startswith('T'))

## any

The `Any` aggregation works like Underscore’s `any`.

    true_or_false = table.aggregate(Any('salaries', lambda d: d > 100000))

You can also use `Table.where()` to filter to columns that pass the truth test.

## all

The `All` aggregation works like Underscore’s `all`.

    true_or_false = table.aggregate(All('salaries', lambda d: d > 100000))