philiprehberger-maybe 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +11 -0
- data/lib/philiprehberger/maybe/version.rb +1 -1
- data/lib/philiprehberger/maybe.rb +15 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 341d0506aef82e712601101351cdd079ca74fbf324ddced8b42ca4bc0609c52a
|
|
4
|
+
data.tar.gz: 28b5c750f0c5026f97a85028ba053c79c6183829e75d33d9cd8a33de9944be30
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 474569f86325ff1f641682e406dc2717b8846942025eea1f4571d7e0699c2b0b07b5c3d30d6a5c14268676a658a1f87797f6706e3e03620ac6c9d976f24ab11a
|
|
7
|
+
data.tar.gz: 56554006f33e1a9deca84740b1a5f659fa3c54e69d437aac0563a827fbb52d798159a708f0fb022f58feb4ab9528c3c184a787a8c5b8d701fef512bbe0090cec
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.5.0] - 2026-06-14
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Maybe.lift(&block)` — convert any block into a Maybe-returning Proc. Wraps the block's result in `Maybe.wrap` so existing nil-returning helpers can join a Maybe pipeline without manual wrapping at every call site.
|
|
14
|
+
|
|
10
15
|
## [0.4.0] - 2026-05-08
|
|
11
16
|
|
|
12
17
|
### Added
|
data/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
[](https://rubygems.org/gems/philiprehberger-maybe)
|
|
5
5
|
[](https://github.com/philiprehberger/rb-maybe/commits/main)
|
|
6
6
|
|
|
7
|
+

|
|
8
|
+
|
|
7
9
|
Optional/Maybe monad with safe chaining and pattern matching
|
|
8
10
|
|
|
9
11
|
## Requirements
|
|
@@ -174,6 +176,14 @@ outer = Philiprehberger::Maybe.wrap(Philiprehberger::Maybe.wrap(42))
|
|
|
174
176
|
outer.flatten.value # => 42
|
|
175
177
|
```
|
|
176
178
|
|
|
179
|
+
### Lifting Callables
|
|
180
|
+
|
|
181
|
+
```ruby
|
|
182
|
+
safe_parse = Philiprehberger::Maybe.lift { |s| Integer(s, exception: false) }
|
|
183
|
+
safe_parse.call('42') # => Some(42)
|
|
184
|
+
safe_parse.call('abc') # => None
|
|
185
|
+
```
|
|
186
|
+
|
|
177
187
|
## API
|
|
178
188
|
|
|
179
189
|
### `Maybe`
|
|
@@ -185,6 +195,7 @@ outer.flatten.value # => 42
|
|
|
185
195
|
| `.first_some(*maybes)` | Return the first Some, or None if all are None |
|
|
186
196
|
| `.from_bool(condition, value = nil, &block)` | Some when condition is truthy (and value/block result is non-nil), else None |
|
|
187
197
|
| `.try(*error_classes, &block)` | Run block; return Some on success, None on caught errors or nil (defaults to StandardError) |
|
|
198
|
+
| `.lift(&block)` | Return a Proc that wraps the block's result in Some/None |
|
|
188
199
|
|
|
189
200
|
### `Maybe::Some`
|
|
190
201
|
|
|
@@ -62,6 +62,21 @@ module Philiprehberger
|
|
|
62
62
|
None.instance
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
+
# Lift a plain callable into a Maybe-returning callable.
|
|
66
|
+
#
|
|
67
|
+
# Takes a block (or callable) and returns a Proc that wraps the block's
|
|
68
|
+
# result in `Maybe.wrap`. Useful for adapting existing nil-returning Ruby
|
|
69
|
+
# methods into the Maybe pipeline without manually wrapping each call site.
|
|
70
|
+
#
|
|
71
|
+
# @yield arguments forwarded to the block; the block's return value is wrapped
|
|
72
|
+
# @return [Proc] a Proc that returns Some or None
|
|
73
|
+
# @raise [Error] if no block is given
|
|
74
|
+
def self.lift(&block)
|
|
75
|
+
raise Error, 'block is required' unless block
|
|
76
|
+
|
|
77
|
+
->(*args, **kwargs) { wrap(block.call(*args, **kwargs)) }
|
|
78
|
+
end
|
|
79
|
+
|
|
65
80
|
# Container for a present value
|
|
66
81
|
class Some
|
|
67
82
|
include Enumerable
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-maybe
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-06-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A Maybe/Optional type for Ruby providing Some and None containers with
|
|
14
14
|
safe chaining, pattern matching via deconstruct_keys, filtering, and value extraction.
|