Subscribe now to stay up-to-date

Field Hooks Part 2: compute

Published 12/22/2022
Developers
Ashley Mulligan

Ashley Mulligan

Head of Growth Product & Developer Experience in Engineering

Let's continue thinking through more real-world examples to wrap our minds around the possibilities of Flatfile's Field Hooks, which — as their name suggests — clean up or validate data at the field level.


This is Part 2 of a 3-part series about Flatfile's Field Hooks. Read Part 1 - Field Hooks: cast first if you haven't already.


Scene 2: compute

Suppose we need to convert all employee names to lowercase before reasoning about the data strings.

Leveraging recordCompute Field Hooks

We'll use compute to modify the data in place before proceeding to validate.

  1. First, compute will receive data of the type determined by the field's cast hook

  2. Then, it will perform a transformation to the value returned from cast.

    1. Note: compute will always return data of the same type

CODE EXAMPLE

While Field Hooks only clean up or validate data at the field level, recordCompute and batchRecordsCompute come into play when you need to run computations across all fields in a single record or in bulk operations. More on Record Hooks soon.

Check out the docs to learn more about processing data with Flatfile or get started not with CLI Quickstart.

Related posts:

Read more
decorative image of cast field hooks code
Developers

Field Hooks Part 1: cast

Let's think about a real-world example to wrap our minds around the possibilities of Field Hooks, wh...

Read blog post
Read more
decorative image of cast field hooks code
Developers

Field Hooks Part 1: cast

Let's think about a real-world example to wrap our minds around the possibilities of Field Hooks, wh...

Read blog post