Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
omkarmoghe committed Mar 29, 2024
1 parent d34f73b commit 040a3f5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ If bundler is not being used to manage dependencies, install the gem by executin

## Why would I need this?

PortableExpressions can be a powerful tool when designing stateless components. It's useful when you want to transmit the actual _logic_ you want to run (i.e. an `Expression`) along with its inputs. By making your logic or procedure stateless, you can decouple services from one another in interesting and scalable ways.
`PortableExpressions` can be a powerful tool when designing stateless components. It's useful when you want to transmit the actual _logic_ you want to run (i.e. an `Expression`) along with its inputs. By making your logic or procedure stateless, you can decouple services from one another in interesting and scalable ways.

Consider a serverless function (e.g. [AWS Lambda](https://aws.amazon.com/lambda/)) that adds 2 inputs together and some application code that calls it:

Expand All @@ -38,7 +38,7 @@ def multiply(input1, input2)
end
```

But what happens as complexity increases, e.g. you want to run more steps? You could continue to define functions, but it would be a lot simpler if there was a way to tell the function what steps to run, the same way you pass it the inputs. That's where PortableExpressions come in handy:
But what happens as complexity increases, e.g. you want to run more steps? You could continue to define specific functions, but it would be a lot simpler if there was a way to tell the function what steps to run, the same way you tell it what the inputs are. Let's rewrite our function using `PortableExpressions`.

```ruby
# Serverless function
Expand Down Expand Up @@ -71,7 +71,9 @@ inputs = PortableExpressions::Environment.new(
serverless_function_call(:run_expressions, multiply_step.to_json, inputs.to_json) #=> 9
```

This is an oversimplified example to illustrate the kind of code you can write when your logic or procedure is **stateless** and **portable**. Here we demonstrated arithmetic, but the `operator` can be any Ruby method that the `operands` respond to, which means your `Expressions` can do a lot more than just add or multiply numbers.
This is an oversimplified example to illustrate the kind of code you can write when your logic or procedure is **stateless** and **portable**. In your application, the inputs and procedure may come from different sources.

We demonstrated arithmetic in our example, but the `operator` can be _any Ruby method_ that the `operands` respond to, which means your `Expressions` can do a lot more than just add or multiply numbers.

See [example use cases](#example-use-cases) for more ideas.

Expand Down

0 comments on commit 040a3f5

Please sign in to comment.