Type-safe parameters
Declare an operation’s inputs with type constraints, validated at runtime via the Literal gem. A wrong-shape argument fails loudly the moment the operation is built.
Partial application, currying, and operation composition — with runtime type safety and first-class Rails, Dry::Monads, and Action Policy integration.
Declare an operation’s inputs with type constraints, validated at runtime via the Literal gem. A wrong-shape argument fails loudly the moment the operation is built.
Build specialized operations from general ones. Fix some parameters with .with, leave the rest open, or .curry to apply them one at a time.
Chain operations with .then and .or_else for railway-oriented flows, or compose them declaratively with the Pipeline DSL.
Built-in Success/Failure types with no dependencies, or drop in Dry::Monads for Result types and Do notation when you want them.
Generators scaffold your base class and operations. bin/rails g typed_operation:install wires everything up in one step.
Declare authorization inline with action_type and authorized_via. Operations check the policy before perform runs.
TypedOperation is an implementation of the Command pattern: each operation is a small, callable object with explicitly typed parameters. Operations can be partially applied, curried, pattern-matched, and composed into larger flows — so business logic lives in consistent, testable, isolated units.
class GreetUser < TypedOperation::Base
param :name, String
param :greeting, String, default: "Hello"
def perform
"#{greeting}, #{name}!"
end
end
# Direct invocation
GreetUser.call(name: "World")
# => "Hello, World!"
# Partial application
greeter = GreetUser.with(greeting: "Welcome")
greeter.call(name: "Alice")
# => "Welcome, Alice!"
Add this line to your application’s Gemfile:
gem "typed_operation"
For Rails, generate the base operation class:
bin/rails g typed_operation:install
# With optional integrations
bin/rails g typed_operation:install --dry_monads --action_policy