Skip to content

Commit

Permalink
chore: improment README documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
thadeu committed May 12, 2024
1 parent e159f81 commit a88e8fd
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ unreleased | https://github.com/thadeu/zx-result/blob/main/README.md
## Table of Contents <!-- omit in toc -->
- [Installation](#installation)
- [Usage](#usage)
- [Success](#success)
- [Failure](#failure)
- [Try](#try)
- [Given](#given)

## Compatibility

Expand Down Expand Up @@ -60,8 +64,9 @@ Without configuration, because we use only Ruby. ❤️

## Usage

You can use with many towards.

### Success Type
### Success

```ruby
result = Zx.Success(5)
Expand All @@ -82,7 +87,7 @@ result.error #=> nil or raises an exception
result.type #=> :integer
```

### Failure Type
### Failure

```ruby
result = Zx.Failure(:fizz)
Expand Down Expand Up @@ -174,6 +179,27 @@ result = Zx.Success(5, type: :integer)
.on_failure{|error| puts error } #=> 10
```

### Try

```ruby
result = Zx.Try { 5 }
.step{ |number| number + 5 }
.check { |number| number == 15 }
.on_failure{|error| puts error } #=> 10
```

### Given

```ruby
input = 5

result = Zx.Given(input)
.then{ |number| number + 5 }
.then{ |number| number + 5 }
.then{ |number| number + 5 }
.on_success{|number| number }
```

You can use one or multiples listeners in your result. We see some use cases.

**Simple composition**
Expand Down Expand Up @@ -209,7 +235,9 @@ result
**Simple Inherit**

```ruby
class AsInherited < Zx::Result
class AsInherited
include Zx

def pass(...)
Success(...)
end
Expand Down Expand Up @@ -237,24 +265,15 @@ result
You can use directly methods, for example:

```ruby
Zx::Result.Success(relation)

# or

Zx::Result::Success[relation]
Zx.Success(relation)

# or


Zx::Success[relation]
```

```ruby
Zx::Result.Failure('error', type: :invalid)

# or

Zx::Result::Failure[:invalid_user, 'user was not found']
Zx:.Failure('error', type: :invalid)

# or

Expand Down

0 comments on commit a88e8fd

Please sign in to comment.