Torihiki

Torihiki is a simple DSL inspired by dry-transaction gem. It builds a composition of functions which would help you create business transactions without magic.

Torihiki doesn’t include error handling out of the box, but you feel free to use dry-either or anything esle for error handling.

What function composition exactly is?

Usage

Include Torihiki into your class to make it store your composition nclude DSL similar to dry-transaction.

Build simple composition

class Transaction
  include Torihiki
  include Torihiki::Handlers

  map AuthenticationService
  map ValidationService
  map do
    # some operations
  end
  map do
    # persistence operation
  end
end

Transaction.call(context)

Build chainable composition

Usage with Dry::Either

Handlers

tap

def tap(input)
  map do |context|
    input.call(context)
    context
  end
end

reduce / merge

def reduce(input)
  map do |context|
    context.merge(input.call context)
  end
end

try

def try(input)
  map do |context|
    input.call(context)
  rescue
    context
  end
end

either

def either(input)
  map do |context|
    Left(input.call(context))
  rescue error
    Right(error)
  end
end

sequence ???

Contribution Guide