Sha256: aa56556929d89f5163dc8e1abdef8790c0c74f66f7d2ec7bf759f1a324de101c

Contents?: true

Size: 751 Bytes

Versions: 4

Compression:

Stored size: 751 Bytes

Contents

---
title: Case equality
layout: gem-single
name: dry-monads
---

### Case equality

Monads allow to use default ruby `case` operator for matching result:

```ruby
case value
when Some(1), Some(2) then :one_or_two
when Some(3..5) then :three_to_five
else
  :something_else
end
```

You can use specific `Failure` options too:

```ruby
case value
when Success then [:ok, value.value!]
when Failure(TimeoutError) then [:timeout]
when Failure(ConnectionClosed) then [:net_error]
when Failure then [:generic_error]
else
  raise "Unhandled case"
end
```

#### Nested structures

```ruby
case value
when Success(None()) then :nothing
when Success(Some { |x| x > 10 }) then :something
when Success(Some) then :something_else
when Failure then :error
end
```

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-monads-1.3.5 docsite/source/case-equality.html.md
dry-monads-1.3.4 docsite/source/case-equality.html.md
dry-monads-1.3.3 docsite/source/case-equality.html.md
dry-monads-1.3.2 docsite/source/case-equality.html.md