errgonomic 0.9.1 → 0.9.2
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 +12 -0
- data/lib/errgonomic/option.rb +26 -5
- data/lib/errgonomic/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2b6ae05f6601a1d5470b1cb9cd9266e3937b91fd2ea2bab8eeac469959b24e90
|
|
4
|
+
data.tar.gz: 5b3095f01409a6275b500df7d08e0c8b23b50062924d61ada8a4a6c98e0b69fe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a74d4cdf58805801e853a59329b076ca43c553da3a670fc56762fea5d755da898c6a6951e2c697fcb91b28930382d2f0ff6e3e2a85038ad33a5a3a0d4567c6c3
|
|
7
|
+
data.tar.gz: d636451a6addbfc3e2af62974e659fe7de490dd7b4176f3cf2f53c6f93dd6d620244f14e99a684817a160a4715c02ed4b5d0b003bded913f5962e64987d674cc
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.9.2] - 2026-09-10
|
|
4
|
+
|
|
5
|
+
This release makes `Option#and`, `#xor`, `#zip` and `#zip_with` check their operand the way `or` already did.
|
|
6
|
+
|
|
7
|
+
### Upgrading from 0.9.1
|
|
8
|
+
|
|
9
|
+
`Option#and`, `#xor`, `#zip` and `#zip_with` raise `Errgonomic::ArgumentError` on a bare operand, on a `None` receiver as well as a `Some`. Code that passed a bare value to `and` and read it back has to wrap it.
|
|
10
|
+
|
|
11
|
+
### Changes
|
|
12
|
+
|
|
13
|
+
- [Behavior change] `Option#and`, `#xor`, `#zip` and `#zip_with` check their operand the way `or` already did, raising `Errgonomic::ArgumentError` (`other must be an Option, was Integer`) before the receiver's variant is consulted. 0.9.x let `Some(2).and(3)` hand back the bare `3`, let `None().and(3)` and `None().zip(2)` accept the operand silently, and let `Some(1).zip(2)` and `Some(:l).xor(:r)` fall into a bare `NoMethodError` on `some?` or `none?`
|
|
14
|
+
|
|
3
15
|
## [0.9.1] - 2026-09-10
|
|
4
16
|
|
|
5
17
|
This release reverts the 0.9.0 change that made `to_s` render an Option or a Result. The raise is back, with a message that says what to call instead.
|
data/lib/errgonomic/option.rb
CHANGED
|
@@ -594,10 +594,10 @@ module Errgonomic
|
|
|
594
594
|
# @example
|
|
595
595
|
# None().or(Some(1)) # => Some(1)
|
|
596
596
|
# Some(2).or(Some(3)) # => Some(2)
|
|
597
|
-
# None().or(2) # => raise Errgonomic::ArgumentError
|
|
597
|
+
# None().or(2) # => raise Errgonomic::ArgumentError, "other must be an Option, was Integer"
|
|
598
|
+
# Some(1).or(2) # => raise Errgonomic::ArgumentError, "other must be an Option, was Integer"
|
|
598
599
|
def or(other)
|
|
599
|
-
|
|
600
|
-
|
|
600
|
+
option_operand!(other)
|
|
601
601
|
return self if some?
|
|
602
602
|
|
|
603
603
|
other
|
|
@@ -620,12 +620,17 @@ module Errgonomic
|
|
|
620
620
|
val
|
|
621
621
|
end
|
|
622
622
|
|
|
623
|
-
# If self is Some, return the provided other Option.
|
|
623
|
+
# If self is Some, return the provided other Option. The operand is
|
|
624
|
+
# checked on both variants, so a None-heavy path still learns that it
|
|
625
|
+
# was handed a bare value.
|
|
624
626
|
#
|
|
625
627
|
# @example
|
|
626
628
|
# None().and(Some(1)) # => None()
|
|
627
629
|
# Some(2).and(Some(3)) # => Some(3)
|
|
630
|
+
# Some(2).and(3) # => raise Errgonomic::ArgumentError, "other must be an Option, was Integer"
|
|
631
|
+
# None().and(3) # => raise Errgonomic::ArgumentError, "other must be an Option, was Integer"
|
|
628
632
|
def and(other)
|
|
633
|
+
option_operand!(other)
|
|
629
634
|
return self if none?
|
|
630
635
|
|
|
631
636
|
other
|
|
@@ -657,7 +662,10 @@ module Errgonomic
|
|
|
657
662
|
# None().zip(Some(1)) # => None()
|
|
658
663
|
# Some(1).zip(None()) # => None()
|
|
659
664
|
# Some(2).zip(Some(3)) # => Some([2, 3])
|
|
665
|
+
# Some(1).zip(2) # => raise Errgonomic::ArgumentError, "other must be an Option, was Integer"
|
|
666
|
+
# None().zip(2) # => raise Errgonomic::ArgumentError, "other must be an Option, was Integer"
|
|
660
667
|
def zip(other)
|
|
668
|
+
option_operand!(other)
|
|
661
669
|
return None() unless some? && other.some?
|
|
662
670
|
|
|
663
671
|
Some([value, other.value])
|
|
@@ -671,7 +679,10 @@ module Errgonomic
|
|
|
671
679
|
# None().zip_with(Some(1)) { |a, b| a + b } # => None()
|
|
672
680
|
# Some(1).zip_with(None()) { |a, b| a + b } # => None()
|
|
673
681
|
# Some(2).zip_with(Some(3)) { |a, b| a + b } # => Some(5)
|
|
682
|
+
# Some(1).zip_with(2) { |a, b| a + b } # => raise Errgonomic::ArgumentError, "other must be an Option, was Integer"
|
|
683
|
+
# None().zip_with(2) { |a, b| a + b } # => raise Errgonomic::ArgumentError, "other must be an Option, was Integer"
|
|
674
684
|
def zip_with(other, &block)
|
|
685
|
+
option_operand!(other)
|
|
675
686
|
return None() unless some? && other.some?
|
|
676
687
|
|
|
677
688
|
other = block.call(value, other.value)
|
|
@@ -767,8 +778,10 @@ module Errgonomic
|
|
|
767
778
|
# Some(:left).xor(Some(:right)) # => None()
|
|
768
779
|
# Some(:left).xor(None()) #=> Some(:left)
|
|
769
780
|
# None().xor(Some(:right)) #=> Some(:right)
|
|
770
|
-
#
|
|
781
|
+
# Some(:left).xor(:right) # => raise Errgonomic::ArgumentError, "other must be an Option, was Symbol"
|
|
782
|
+
# None().xor(:right) # => raise Errgonomic::ArgumentError, "other must be an Option, was Symbol"
|
|
771
783
|
def xor(other)
|
|
784
|
+
option_operand!(other)
|
|
772
785
|
return self if some? && other.none?
|
|
773
786
|
return other if other.some? && none?
|
|
774
787
|
|
|
@@ -777,6 +790,14 @@ module Errgonomic
|
|
|
777
790
|
|
|
778
791
|
private
|
|
779
792
|
|
|
793
|
+
# Checked before the discriminant is consulted, so a None-heavy path
|
|
794
|
+
# learns about a bare operand as soon as a Some-heavy one would.
|
|
795
|
+
def option_operand!(other)
|
|
796
|
+
return if other.is_a?(Errgonomic::Option::Any)
|
|
797
|
+
|
|
798
|
+
raise Errgonomic::ArgumentError, "other must be an Option, was #{other.class.name}"
|
|
799
|
+
end
|
|
800
|
+
|
|
780
801
|
def to_s_refusal
|
|
781
802
|
"#{bounded_inspect} refuses to_s; use inspect for a log line, or unwrap_or / expect! for the value"
|
|
782
803
|
end
|
data/lib/errgonomic/version.rb
CHANGED