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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 518036f3926caf1ec9b91a02bf0dfb954cd7dfbf5c6f9f622a434f99e4927dd7
4
- data.tar.gz: 4689a03b925f43adb753c1367feba52208caad03b42fcb14e5faabfa88d464bd
3
+ metadata.gz: 341d0506aef82e712601101351cdd079ca74fbf324ddced8b42ca4bc0609c52a
4
+ data.tar.gz: 28b5c750f0c5026f97a85028ba053c79c6183829e75d33d9cd8a33de9944be30
5
5
  SHA512:
6
- metadata.gz: 7ee4093ef79f5a1a8a9d8b3b79260fbc76091c0118334f5ec3066666cf3e763cdc901e50b2e490d3495d06c71caf314a86383d97161e4d6c93ceb908358be4e0
7
- data.tar.gz: e24c606281efb3faef61b85e23661ee6172c2b223e4d59535a3150b13617b796d8a66c88945a1bf18a6259cc176de830816bfcc2bbea0ae6d479846b90824e97
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
  [![Gem Version](https://badge.fury.io/rb/philiprehberger-maybe.svg)](https://rubygems.org/gems/philiprehberger-maybe)
5
5
  [![Last updated](https://img.shields.io/github/last-commit/philiprehberger/rb-maybe)](https://github.com/philiprehberger/rb-maybe/commits/main)
6
6
 
7
+ ![philiprehberger-maybe](https://raw.githubusercontent.com/philiprehberger/rb-maybe/main/package-card.webp)
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
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module Maybe
5
- VERSION = '0.4.0'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
@@ -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.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-05-08 00:00:00.000000000 Z
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.