Here's a quick example of how you could use Blots to interactively compute some basic statistics about the weather forecast for the next 7 days in Denver, CO:
First, we'll grab the forecast for Denver from the National Weather Service API and pass the response to Blots as an input. We'll also use the --output flag to provide a filename to write the outputs to (this is optional; if we didn't provide a filename, the outputs would just be written to stdout):
blots --input "$(curl -s https://api.weather.gov/gridpoints/BOU/63,62/forecast)" --output weather.json
Since we provided neither a source file nor some inline code, Blots will open up in interactive mode. We can now use the inputs record to access the forecast data and bind it to a name ( forecasts ):
> forecasts = inputs.properties.periods = [{detailedForecast: "A chance of showers and thunderstorms... (truncated)
Next, we'll grab the temperatures from the forecasts by mapping over the list. We can use Blots's via operator to apply a function to each element of the list. Our function will take just the forecasted tempeature for that period and return it, so the whole expression evaluates to a new list containing only the temperatures:
> temps = forecasts via forecast => forecast.temperature = [52, 71, 49, 73, 49, 80, 53, 85, 56, 83, 56, 83, 54, 86]
Now we can compute the average temperature using Blots's avg function. We want to include this in our output file weather.json , so we'll use the output keyword to bind the result to a name and record it in the outputs:
> output average = avg(temps) = 66.42857142857143 [output 'average' recorded]
Let's do the same for the minimum and maximum temperatures:
> output minimum = min(temps) = 49 [output 'minimum' recorded] > output maximum = max(temps) = 86 [output 'maximum' recorded]
We can now exit Blots (by typing exit or hitting Ctrl + c ). Let's take a look at the output file:
cat weather.json {"average":66.42857142857143,"minimum":49.0,"maximum":86.0}