linguadata 0.1.1 → 0.1.3

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: 2042e08625e0a7b40800f328540e6d180ada08331d4cac04899d432cd5663d5a
4
- data.tar.gz: e888738880b183d226e258248d9315c6f3b12d05d5aa421b5d85bc807eebe4de
3
+ metadata.gz: 19c3b2ee58bec38f656da894f3451359003d5ffa3c1eb5d88f04d785045ffe03
4
+ data.tar.gz: 90d39bda8a6e4d4b3d5471ab95da02d93a7456370f65f05dc7b414db12444ca2
5
5
  SHA512:
6
- metadata.gz: 6d002bbc8ad073beedc8314c60f7d1a83731c382057d49e2cb9bfc58d70a0f6d898d0c6f0e2ea0e8b812b2a55c4b202eca50a3381f4d975ac7876265f71c2e59
7
- data.tar.gz: '005090ea3dfbd9a31a16f574c5384cda251ba615e8693445a0d86e8bfb5a8df381a46f6ea4f8eedd4902ca7e4eba622777a0c06ae19dbb39b2cd8865cc7656aa'
6
+ metadata.gz: 2a61866d502824d73ff82286d4187f79a2db950ececa50482c5b722db08bd8c04c3e730d4f28a95d5dc610c80271ded81c70ce9594c22210c0e8a17dfdaf51a3
7
+ data.tar.gz: 7c0c2a3931d87cf6e4baf36daa792055411dbb6642b557629f33b4ead1f296deb3b4f65158814600d52924558322046b0a15ad0a831e5af74c19c865919b5714
data/.idea/linguadata.iml CHANGED
@@ -8,74 +8,81 @@
8
8
  <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
9
  <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
10
  <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
+ <excludeFolder url="file://$MODULE_DIR$/coverage" />
12
+ <excludeFolder url="file://$MODULE_DIR$/pkg" />
11
13
  </content>
12
14
  <orderEntry type="jdk" jdkName="rbenv: 3.2.2" jdkType="RUBY_SDK" />
13
15
  <orderEntry type="sourceFolder" forTests="false" />
14
- <orderEntry type="library" scope="PROVIDED" name="activesupport (v7.1.1, rbenv: 3.2.2) [gem]" level="application" />
15
- <orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, rbenv: 3.2.2) [gem]" level="application" />
16
- <orderEntry type="library" scope="PROVIDED" name="bigdecimal (v3.1.4, rbenv: 3.2.2) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="activesupport (v7.1.1, rbenv: 3.2.2, linguadata) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, rbenv: 3.2.2, linguadata) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="bigdecimal (v3.1.4, rbenv: 3.2.2, linguadata) [gem]" level="application" />
17
19
  <orderEntry type="library" scope="PROVIDED" name="bundler (v2.4.10, rbenv: 3.2.2) [gem]" level="application" />
18
- <orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.2.2, rbenv: 3.2.2) [gem]" level="application" />
19
- <orderEntry type="library" scope="PROVIDED" name="connection_pool (v2.4.1, rbenv: 3.2.2) [gem]" level="application" />
20
- <orderEntry type="library" scope="PROVIDED" name="csv (v3.2.7, rbenv: 3.2.2) [gem]" level="application" />
21
- <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.5.0, rbenv: 3.2.2) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.2.2, rbenv: 3.2.2, linguadata) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="connection_pool (v2.4.1, rbenv: 3.2.2, linguadata) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="csv (v3.2.7, rbenv: 3.2.2, linguadata) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.5.0, rbenv: 3.2.2, linguadata) [gem]" level="application" />
22
24
  <orderEntry type="library" scope="PROVIDED" name="drb (v2.1.1, rbenv: 3.2.2) [gem]" level="application" />
23
- <orderEntry type="library" scope="PROVIDED" name="ffi (v1.16.3, rbenv: 3.2.2) [gem]" level="application" />
24
- <orderEntry type="library" scope="PROVIDED" name="fileutils (v1.7.1, rbenv: 3.2.2) [gem]" level="application" />
25
- <orderEntry type="library" scope="PROVIDED" name="i18n (v1.14.1, rbenv: 3.2.2) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="ffi (v1.16.3, rbenv: 3.2.2, linguadata) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="fileutils (v1.7.1, rbenv: 3.2.2, linguadata) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="i18n (v1.14.1, rbenv: 3.2.2, linguadata) [gem]" level="application" />
26
28
  <orderEntry type="library" scope="PROVIDED" name="json (v2.6.3, rbenv: 3.2.2) [gem]" level="application" />
27
- <orderEntry type="library" scope="PROVIDED" name="language_server-protocol (v3.17.0.3, rbenv: 3.2.2) [gem]" level="application" />
28
- <orderEntry type="library" scope="PROVIDED" name="lint_roller (v1.1.0, rbenv: 3.2.2) [gem]" level="application" />
29
- <orderEntry type="library" scope="PROVIDED" name="listen (v3.8.0, rbenv: 3.2.2) [gem]" level="application" />
29
+ <orderEntry type="library" scope="PROVIDED" name="language_server-protocol (v3.17.0.3, rbenv: 3.2.2, linguadata) [gem]" level="application" />
30
+ <orderEntry type="library" scope="PROVIDED" name="lint_roller (v1.1.0, rbenv: 3.2.2, linguadata) [gem]" level="application" />
31
+ <orderEntry type="library" scope="PROVIDED" name="listen (v3.8.0, rbenv: 3.2.2, linguadata) [gem]" level="application" />
30
32
  <orderEntry type="library" scope="PROVIDED" name="logger (v1.5.3, rbenv: 3.2.2) [gem]" level="application" />
31
- <orderEntry type="library" scope="PROVIDED" name="minitest (v5.20.0, rbenv: 3.2.2) [gem]" level="application" />
32
- <orderEntry type="library" scope="PROVIDED" name="parallel (v1.23.0, rbenv: 3.2.2) [gem]" level="application" />
33
- <orderEntry type="library" scope="PROVIDED" name="parser (v3.2.2.4, rbenv: 3.2.2) [gem]" level="application" />
34
- <orderEntry type="library" scope="PROVIDED" name="racc (v1.7.1, rbenv: 3.2.2) [gem]" level="application" />
35
- <orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, rbenv: 3.2.2) [gem]" level="application" />
33
+ <orderEntry type="library" scope="PROVIDED" name="minitest (v5.20.0, rbenv: 3.2.2, linguadata) [gem]" level="application" />
34
+ <orderEntry type="library" scope="PROVIDED" name="mutant (v0.11.24, rbenv: 3.2.2, linguadata) [gem]" level="application" />
35
+ <orderEntry type="library" scope="PROVIDED" name="mutant-license (v0.1.1.2.0526686720282068589522783053343094335875.0, rbenv: 3.2.2, linguadata) [gem]" level="application" />
36
+ <orderEntry type="library" scope="PROVIDED" name="mutant-rspec (v0.11.24, rbenv: 3.2.2, linguadata) [gem]" level="application" />
37
+ <orderEntry type="library" scope="PROVIDED" name="parallel (v1.23.0, rbenv: 3.2.2, linguadata) [gem]" level="application" />
38
+ <orderEntry type="library" scope="PROVIDED" name="parser (v3.2.2.4, rbenv: 3.2.2, linguadata) [gem]" level="application" />
39
+ <orderEntry type="library" scope="PROVIDED" name="racc (v1.7.1, rbenv: 3.2.2, linguadata) [gem]" level="application" />
40
+ <orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, rbenv: 3.2.2, linguadata) [gem]" level="application" />
36
41
  <orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, rbenv: 3.2.2) [gem]" level="application" />
37
- <orderEntry type="library" scope="PROVIDED" name="rb-fsevent (v0.11.2, rbenv: 3.2.2) [gem]" level="application" />
38
- <orderEntry type="library" scope="PROVIDED" name="rb-inotify (v0.10.1, rbenv: 3.2.2) [gem]" level="application" />
39
- <orderEntry type="library" scope="PROVIDED" name="rbs (v3.2.2, rbenv: 3.2.2) [gem]" level="application" />
40
- <orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.8.2, rbenv: 3.2.2) [gem]" level="application" />
41
- <orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.6, rbenv: 3.2.2) [gem]" level="application" />
42
- <orderEntry type="library" scope="PROVIDED" name="rspec (v3.12.0, rbenv: 3.2.2) [gem]" level="application" />
43
- <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.12.2, rbenv: 3.2.2) [gem]" level="application" />
44
- <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.12.3, rbenv: 3.2.2) [gem]" level="application" />
45
- <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.12.6, rbenv: 3.2.2) [gem]" level="application" />
46
- <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.12.1, rbenv: 3.2.2) [gem]" level="application" />
47
- <orderEntry type="library" scope="PROVIDED" name="rubocop (v1.56.4, rbenv: 3.2.2) [gem]" level="application" />
48
- <orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.29.0, rbenv: 3.2.2) [gem]" level="application" />
49
- <orderEntry type="library" scope="PROVIDED" name="rubocop-performance (v1.19.1, rbenv: 3.2.2) [gem]" level="application" />
50
- <orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.13.0, rbenv: 3.2.2) [gem]" level="application" />
51
- <orderEntry type="library" scope="PROVIDED" name="standard (v1.31.2, rbenv: 3.2.2) [gem]" level="application" />
52
- <orderEntry type="library" scope="PROVIDED" name="standard-custom (v1.0.2, rbenv: 3.2.2) [gem]" level="application" />
53
- <orderEntry type="library" scope="PROVIDED" name="standard-performance (v1.2.1, rbenv: 3.2.2) [gem]" level="application" />
54
- <orderEntry type="library" scope="PROVIDED" name="steep (v1.5.3, rbenv: 3.2.2) [gem]" level="application" />
55
- <orderEntry type="library" scope="PROVIDED" name="strscan (v3.0.7, rbenv: 3.2.2) [gem]" level="application" />
56
- <orderEntry type="library" scope="PROVIDED" name="terminal-table (v3.0.2, rbenv: 3.2.2) [gem]" level="application" />
57
- <orderEntry type="library" scope="PROVIDED" name="tzinfo (v2.0.6, rbenv: 3.2.2) [gem]" level="application" />
58
- <orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.5.0, rbenv: 3.2.2) [gem]" level="application" />
42
+ <orderEntry type="library" scope="PROVIDED" name="rb-fsevent (v0.11.2, rbenv: 3.2.2, linguadata) [gem]" level="application" />
43
+ <orderEntry type="library" scope="PROVIDED" name="rb-inotify (v0.10.1, rbenv: 3.2.2, linguadata) [gem]" level="application" />
44
+ <orderEntry type="library" scope="PROVIDED" name="rbs (v3.2.2, rbenv: 3.2.2, linguadata) [gem]" level="application" />
45
+ <orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.8.2, rbenv: 3.2.2, linguadata) [gem]" level="application" />
46
+ <orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.6, rbenv: 3.2.2, linguadata) [gem]" level="application" />
47
+ <orderEntry type="library" scope="PROVIDED" name="rspec (v3.12.0, rbenv: 3.2.2, linguadata) [gem]" level="application" />
48
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.12.2, rbenv: 3.2.2, linguadata) [gem]" level="application" />
49
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.12.3, rbenv: 3.2.2, linguadata) [gem]" level="application" />
50
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.12.6, rbenv: 3.2.2, linguadata) [gem]" level="application" />
51
+ <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.12.1, rbenv: 3.2.2, linguadata) [gem]" level="application" />
52
+ <orderEntry type="library" scope="PROVIDED" name="rubocop (v1.56.4, rbenv: 3.2.2, linguadata) [gem]" level="application" />
53
+ <orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.29.0, rbenv: 3.2.2, linguadata) [gem]" level="application" />
54
+ <orderEntry type="library" scope="PROVIDED" name="rubocop-performance (v1.19.1, rbenv: 3.2.2, linguadata) [gem]" level="application" />
55
+ <orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.13.0, rbenv: 3.2.2, linguadata) [gem]" level="application" />
56
+ <orderEntry type="library" scope="PROVIDED" name="sorbet-runtime (v0.5.11120, rbenv: 3.2.2, linguadata) [gem]" level="application" />
57
+ <orderEntry type="library" scope="PROVIDED" name="standard (v1.31.2, rbenv: 3.2.2, linguadata) [gem]" level="application" />
58
+ <orderEntry type="library" scope="PROVIDED" name="standard-custom (v1.0.2, rbenv: 3.2.2, linguadata) [gem]" level="application" />
59
+ <orderEntry type="library" scope="PROVIDED" name="standard-performance (v1.2.1, rbenv: 3.2.2, linguadata) [gem]" level="application" />
60
+ <orderEntry type="library" scope="PROVIDED" name="steep (v1.5.3, rbenv: 3.2.2, linguadata) [gem]" level="application" />
61
+ <orderEntry type="library" scope="PROVIDED" name="strscan (v3.0.7, rbenv: 3.2.2, linguadata) [gem]" level="application" />
62
+ <orderEntry type="library" scope="PROVIDED" name="terminal-table (v3.0.2, rbenv: 3.2.2, linguadata) [gem]" level="application" />
63
+ <orderEntry type="library" scope="PROVIDED" name="tzinfo (v2.0.6, rbenv: 3.2.2, linguadata) [gem]" level="application" />
64
+ <orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.5.0, rbenv: 3.2.2, linguadata) [gem]" level="application" />
65
+ <orderEntry type="library" scope="PROVIDED" name="unparser (v0.6.10, rbenv: 3.2.2, linguadata) [gem]" level="application" />
59
66
  </component>
60
67
  <component name="RakeTasksCache">
61
68
  <option name="myRootTask">
62
69
  <RakeTaskImpl id="rake">
63
70
  <subtasks>
64
- <RakeTaskImpl description="Build linguadata-0.1.0.gem into the pkg directory" fullCommand="build" id="build" />
71
+ <RakeTaskImpl description="Build linguadata-0.1.2.gem into the pkg directory" fullCommand="build" id="build" />
65
72
  <RakeTaskImpl id="build">
66
73
  <subtasks>
67
- <RakeTaskImpl description="Generate SHA512 checksum if linguadata-0.1.0.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
74
+ <RakeTaskImpl description="Generate SHA512 checksum if linguadata-0.1.2.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
68
75
  </subtasks>
69
76
  </RakeTaskImpl>
70
77
  <RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
71
78
  <RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
72
- <RakeTaskImpl description="Build and install linguadata-0.1.0.gem into system gems" fullCommand="install" id="install" />
79
+ <RakeTaskImpl description="Build and install linguadata-0.1.2.gem into system gems" fullCommand="install" id="install" />
73
80
  <RakeTaskImpl id="install">
74
81
  <subtasks>
75
- <RakeTaskImpl description="Build and install linguadata-0.1.0.gem into system gems without network access" fullCommand="install:local" id="local" />
82
+ <RakeTaskImpl description="Build and install linguadata-0.1.2.gem into system gems without network access" fullCommand="install:local" id="local" />
76
83
  </subtasks>
77
84
  </RakeTaskImpl>
78
- <RakeTaskImpl description="Create tag v0.1.0 and build and push linguadata-0.1.0.gem to TODO: Set to your gem server 'https://example.com'" fullCommand="release[remote]" id="release[remote]" />
85
+ <RakeTaskImpl description="Create tag v0.1.2 and build and push linguadata-0.1.2.gem to https://rubygems.org" fullCommand="release[remote]" id="release[remote]" />
79
86
  <RakeTaskImpl description="Run RSpec code examples" fullCommand="spec" id="spec" />
80
87
  <RakeTaskImpl description="Lint with the Standard Ruby style guide" fullCommand="standard" id="standard" />
81
88
  <RakeTaskImpl id="standard">
@@ -93,6 +100,7 @@
93
100
  <RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
94
101
  </subtasks>
95
102
  </RakeTaskImpl>
103
+ <RakeTaskImpl description="" fullCommand="typecheck" id="typecheck" />
96
104
  </subtasks>
97
105
  </RakeTaskImpl>
98
106
  </option>
data/.idea/misc.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="RbsRubysigsRootManager">
4
+ <isRbsGemPresent>true</isRbsGemPresent>
5
+ </component>
6
+ </project>
data/Gemfile CHANGED
@@ -14,4 +14,9 @@ group :development do
14
14
  gem "rspec"
15
15
 
16
16
  gem "standard"
17
+
18
+ gem "mutant-rspec"
19
+ source 'https://oss:7Cp4pNQG3WbtluEGXnLC2QmucJ17q7Zw@gem.mutant.dev' do
20
+ gem 'mutant-license'
21
+ end
17
22
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- linguadata (0.1.1)
4
+ linguadata (0.1.3)
5
+
6
+ GEM
7
+ remote: https://oss:7Cp4pNQG3WbtluEGXnLC2QmucJ17q7Zw@gem.mutant.dev/
8
+ specs:
9
+ mutant-license (0.1.1.2.0526686720282068589522783053343094335875.0)
5
10
 
6
11
  GEM
7
12
  remote: https://rubygems.org/
@@ -37,6 +42,15 @@ GEM
37
42
  rb-inotify (~> 0.9, >= 0.9.10)
38
43
  logger (1.5.3)
39
44
  minitest (5.20.0)
45
+ mutant (0.11.24)
46
+ diff-lcs (~> 1.3)
47
+ parser (~> 3.2.2, >= 3.2.2.4)
48
+ regexp_parser (~> 2.8.2)
49
+ sorbet-runtime (~> 0.5.0)
50
+ unparser (~> 0.6.9)
51
+ mutant-rspec (0.11.24)
52
+ mutant (= 0.11.24)
53
+ rspec-core (>= 3.8.0, < 4.0.0)
40
54
  mutex_m (0.1.2)
41
55
  parallel (1.23.0)
42
56
  parser (3.2.2.4)
@@ -84,6 +98,7 @@ GEM
84
98
  ruby-progressbar (1.13.0)
85
99
  ruby2_keywords (0.0.5)
86
100
  securerandom (0.2.2)
101
+ sorbet-runtime (0.5.11120)
87
102
  standard (1.31.2)
88
103
  language_server-protocol (~> 3.17.0.2)
89
104
  lint_roller (~> 1.0)
@@ -117,6 +132,9 @@ GEM
117
132
  tzinfo (2.0.6)
118
133
  concurrent-ruby (~> 1.0)
119
134
  unicode-display_width (2.5.0)
135
+ unparser (0.6.10)
136
+ diff-lcs (~> 1.3)
137
+ parser (>= 3.2.2.4)
120
138
 
121
139
  PLATFORMS
122
140
  arm64-darwin-23
@@ -124,6 +142,8 @@ PLATFORMS
124
142
 
125
143
  DEPENDENCIES
126
144
  linguadata!
145
+ mutant-license!
146
+ mutant-rspec
127
147
  rake
128
148
  rbs
129
149
  rspec
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Rust's `Result` and `Option` types for Ruby. Properly type annotated.
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/linguadata.svg)](https://badge.fury.io/rb/linguadata)
6
+
5
7
  ## Installation
6
8
 
7
9
  Install the gem and add to the application's Gemfile by executing:
data/Rakefile CHANGED
@@ -11,4 +11,8 @@ task :typecheck do
11
11
  sh "steep check"
12
12
  end
13
13
 
14
- task default: %i[typecheck spec]
14
+ task :mutant do
15
+ sh "mutant run --require linguadata --integration rspec -- 'Linguadata*'"
16
+ end
17
+
18
+ task default: %i[typecheck spec mutant]
@@ -1,6 +1,5 @@
1
- # typed: strict
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module Linguadata
5
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
6
5
  end
data/lib/linguadata.rb CHANGED
@@ -1,4 +1,3 @@
1
- # typed: strict
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require_relative "linguadata/version"
@@ -6,21 +5,31 @@ require_relative "linguadata/version"
6
5
  module Linguadata
7
6
  module Option
8
7
  class Some < Data.define(:value)
9
- def unwrap = value
10
-
11
- def map(&block) = Some[block.call(value)]
8
+ alias_method :unwrap, :value
12
9
 
13
10
  def some? = true
14
11
 
15
12
  def none? = false
16
13
 
17
- def unwrap_or_else(&_block) = value
18
-
19
14
  def unwrap_or(_other) = value
20
15
 
21
- def and_then(&block) = block.call(value)
16
+ def unwrap_or_else(&block)
17
+ raise RequiredBlockError if block.nil?
18
+ value
19
+ end
20
+
21
+ def map(&block)
22
+ raise RequiredBlockError if block.nil?
23
+ Some[block.call(value)]
24
+ end
25
+
26
+ def and_then(&block)
27
+ raise RequiredBlockError if block.nil?
28
+ block.call(value)
29
+ end
22
30
 
23
31
  def filter(&block)
32
+ raise RequiredBlockError if block.nil?
24
33
  if block.call(value)
25
34
  self
26
35
  else
@@ -30,26 +39,38 @@ module Linguadata
30
39
  end
31
40
 
32
41
  class None < Data.define
33
- def value = raise "Cannot get value from None"
34
-
35
- def unwrap = value
42
+ def value = raise NoValueError
36
43
 
37
- def map(&_block) = self
44
+ alias_method :unwrap, :value
38
45
 
39
46
  def some? = false
40
47
 
41
48
  def none? = true
42
49
 
43
- def unwrap_or_else(&block) = block.call
44
-
45
50
  def unwrap_or(other) = other
46
51
 
47
- def and_then(&_block) = self
52
+ def unwrap_or_else(&block)
53
+ raise RequiredBlockError if block.nil?
54
+ block.call
55
+ end
56
+
57
+ def map(&block)
58
+ raise RequiredBlockError if block.nil?
59
+ self
60
+ end
48
61
 
49
- def filter(&_block) = self
62
+ def and_then(&block)
63
+ raise RequiredBlockError if block.nil?
64
+ self
65
+ end
66
+
67
+ def filter(&block)
68
+ raise RequiredBlockError if block.nil?
69
+ self
70
+ end
50
71
  end
51
72
 
52
- def from_nillable(value)
73
+ def self.from_nillable(value)
53
74
  case value
54
75
  in nil
55
76
  None[]
@@ -57,15 +78,20 @@ module Linguadata
57
78
  Some[value]
58
79
  end
59
80
  end
81
+
82
+ class NoValueError < StandardError
83
+ def initialize(_msg = "Attempted to access a value from 'None', which does not hold any value.")
84
+ super
85
+ end
86
+ end
60
87
  end
61
88
 
62
89
  module Result
63
90
  class Success < Data.define(:value)
64
- def error = raise "Cannot get error from Success"
65
-
66
- def unwrap = value
91
+ def error = raise NoErrorInSuccessError
67
92
 
68
- def unwrap_failure = error
93
+ alias_method :unwrap, :value
94
+ alias_method :unwrap_failure, :error
69
95
 
70
96
  def success? = true
71
97
 
@@ -75,19 +101,32 @@ module Linguadata
75
101
 
76
102
  def failure = Option::None[]
77
103
 
78
- def map(&block) = Success[block.call(value)]
104
+ def map(&block)
105
+ raise RequiredBlockError if block.nil?
106
+ Success[block.call(value)]
107
+ end
79
108
 
80
- def map_failure(&_block) = self
109
+ def map_failure(&block)
110
+ raise RequiredBlockError if block.nil?
111
+ self
112
+ end
81
113
 
82
- def and_then(&block) = block.call(value)
114
+ def and_then(&block)
115
+ raise RequiredBlockError if block.nil?
116
+ block.call(value)
117
+ end
118
+
119
+ def or_else(&block)
120
+ raise RequiredBlockError if block.nil?
121
+ self
122
+ end
83
123
  end
84
124
 
85
125
  class Failure < Data.define(:error)
86
- def value = raise "Cannot get value from Failure"
126
+ def value = raise NoValueInFailureError
87
127
 
88
- def unwrap = value
89
-
90
- def unwrap_failure = error
128
+ alias_method :unwrap, :value
129
+ alias_method :unwrap_failure, :error
91
130
 
92
131
  def success? = false
93
132
 
@@ -97,11 +136,43 @@ module Linguadata
97
136
 
98
137
  def failure = Option::Some[error]
99
138
 
100
- def map(&_block) = self
139
+ def map(&block)
140
+ raise RequiredBlockError if block.nil?
141
+ self
142
+ end
143
+
144
+ def map_failure(&block)
145
+ raise RequiredBlockError if block.nil?
146
+ Failure[block.call(error)]
147
+ end
148
+
149
+ def and_then(&block)
150
+ raise RequiredBlockError if block.nil?
151
+ self
152
+ end
153
+
154
+ def or_else(&block)
155
+ raise RequiredBlockError if block.nil?
156
+ block.call(error)
157
+ end
158
+ end
159
+
160
+ class NoErrorInSuccessError < StandardError
161
+ def initialize(_msg = "Attempted to access an error from 'Success', which represents a successful outcome without errors.")
162
+ super
163
+ end
164
+ end
101
165
 
102
- def map_failure(&block) = Failure[block.call(error)]
166
+ class NoValueInFailureError < StandardError
167
+ def initialize(_msg = "Attempted to access a value from 'Failure', which only contains an error.")
168
+ super
169
+ end
170
+ end
171
+ end
103
172
 
104
- def and_then(&_block) = self
173
+ class RequiredBlockError < ArgumentError
174
+ def initialize(_msg = "A block was required but not passed")
175
+ super
105
176
  end
106
177
  end
107
178
  end
data/sig/linguadata.rbs CHANGED
@@ -3,26 +3,22 @@ module Linguadata
3
3
 
4
4
  module DataHelpers
5
5
  class ZeroItemData < Data
6
- def self.new: () -> instance
7
-
8
- def self.[]: () -> instance
9
-
10
6
  def deconstruct: () -> [ ]
11
7
 
12
8
  def deconstruct_keys: (?Array[Symbol]?) -> { }
13
9
  end
14
10
 
15
- class OneItemData[T] < Data
11
+ class OneItemData[out T] < Data
16
12
  def deconstruct: () -> [T]
17
13
 
18
- def deconstruct_keys: (?Array[Symbol]?) -> { Symbol: T }
14
+ def deconstruct_keys: (?Array[Symbol]?) -> ({ } | { Symbol: T })
19
15
  end
20
16
  end
21
17
 
22
18
  module Option
23
- type option[T] = Some[T] | None
19
+ type option[out T] = Some[T] | None
24
20
 
25
- class Some[T] < DataHelpers::OneItemData[T]
21
+ class Some[out T] < DataHelpers::OneItemData[T]
26
22
  include _Option[T]
27
23
 
28
24
  def self.new: [T] (T) -> Some[T]
@@ -32,35 +28,42 @@ module Linguadata
32
28
 
33
29
  class None < DataHelpers::ZeroItemData
34
30
  include _Option[bot]
31
+
32
+ def self.new: () -> None
33
+
34
+ def self.[]: () -> None
35
35
  end
36
36
 
37
- interface _Option[T]
37
+ interface _Option[out T]
38
38
  def value: () -> T
39
39
 
40
- def unwrap: () -> T
40
+ alias unwrap value
41
41
 
42
42
  def some?: () -> bool
43
43
 
44
44
  def none?: () -> bool
45
45
 
46
- def map: [U] { (T) -> U } -> option[U]
47
-
48
46
  def unwrap_or: [U] (U) -> (T | U)
49
47
 
50
48
  def unwrap_or_else: [U] { () -> U } -> (T | U)
51
49
 
50
+ def map: [U] { (T) -> U } -> option[U]
51
+
52
52
  def and_then: [U] { (T) -> option[U] } -> option[U]
53
53
 
54
54
  def filter: { (T) -> bool } -> option[T]
55
55
  end
56
56
 
57
- def from_nillable: [T] (T? value) -> option[T]
57
+ def self.from_nillable: [T] (T? value) -> option[T]
58
+
59
+ class NoValueError < StandardError
60
+ end
58
61
  end
59
62
 
60
63
  module Result
61
- type result[T, E] = Success[T] | Failure[E]
64
+ type result[out T, out E] = Success[T] | Failure[E]
62
65
 
63
- class Success[T] < DataHelpers::OneItemData[T]
66
+ class Success[out T] < DataHelpers::OneItemData[T]
64
67
  include _Result[T, bot]
65
68
 
66
69
  def self.new: [T] (T) -> Success[T]
@@ -68,7 +71,7 @@ module Linguadata
68
71
  def self.[]: [T] (T) -> Success[T]
69
72
  end
70
73
 
71
- class Failure[E] < DataHelpers::OneItemData[E]
74
+ class Failure[out E] < DataHelpers::OneItemData[E]
72
75
  include _Result[bot, E]
73
76
 
74
77
  def self.new: [E] (E) -> Failure[E]
@@ -76,14 +79,13 @@ module Linguadata
76
79
  def self.[]: [E] (E) -> Failure[E]
77
80
  end
78
81
 
79
- interface _Result[T, E]
82
+ interface _Result[out T, out E]
80
83
  def value: () -> T
81
84
 
82
85
  def error: () -> E
83
86
 
84
- def unwrap: () -> T
85
-
86
- def unwrap_failure: () -> E
87
+ alias unwrap value
88
+ alias unwrap_failure error
87
89
 
88
90
  def success?: () -> bool
89
91
 
@@ -97,7 +99,18 @@ module Linguadata
97
99
 
98
100
  def map_failure: [F] { (E) -> F } -> result[T, F]
99
101
 
100
- def and_then: [U] { (T) -> result[U, E] } -> result[U, E]
102
+ def and_then: [U, F] { (T) -> result[U, F] } -> result[U, E | F]
103
+
104
+ def or_else: [U, F] { (E) -> result[U, F] } -> result[T | U, F]
105
+ end
106
+
107
+ class NoErrorInSuccessError < StandardError
101
108
  end
109
+
110
+ class NoValueInFailureError < StandardError
111
+ end
112
+ end
113
+
114
+ class RequiredBlockError < StandardError
102
115
  end
103
116
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linguadata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Pechersky
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-24 00:00:00.000000000 Z
11
+ date: 2023-11-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Bringing Rust's Result and Option types to Ruby, using the Data class
14
14
  introduced in Ruby 3.2
@@ -22,6 +22,7 @@ files:
22
22
  - ".idea/copyright/profiles_settings.xml"
23
23
  - ".idea/inspectionProfiles/Project_Default.xml"
24
24
  - ".idea/linguadata.iml"
25
+ - ".idea/misc.xml"
25
26
  - ".idea/modules.xml"
26
27
  - ".idea/vcs.xml"
27
28
  - ".rspec"