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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e5dd5bf1efa4f12df029b4084a03a8a16eacac628f9481c35cbac8d03164b0c
4
- data.tar.gz: c61b4e0944afd847636e0e7a1beb44a60793b2124fb9b390cdc408cb3899fb6c
3
+ metadata.gz: 2b6ae05f6601a1d5470b1cb9cd9266e3937b91fd2ea2bab8eeac469959b24e90
4
+ data.tar.gz: 5b3095f01409a6275b500df7d08e0c8b23b50062924d61ada8a4a6c98e0b69fe
5
5
  SHA512:
6
- metadata.gz: bafdcc2538e9603d54fc0452912fddf9f86f912074f9a94dd0af3de3783df26917263cca09d0a5ea9440844016fb3da7190127327602a18506c62723ee81c4d8
7
- data.tar.gz: 43a642d0ebfc22610b0f0ad0fe14f954d23c9b6909cc72e1a4ed56543e7e7d3e3c6e6173ce5443a12f33504045aacc734a5ea922d9a7998d4bd5a03f80a889c7
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.
@@ -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.new, "other must be an Option, was Integer"
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
- raise ArgumentError, "other must be an Option, was #{other.class.name}" unless other.is_a?(Any)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Errgonomic
4
- VERSION = '0.9.1'
4
+ VERSION = '0.9.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: errgonomic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Zadrozny