Skip to content

Commit ef2d98f

Browse files
committed
Add generic type fallback for multiple dispatch! v1.2.4
When you call spelled_out with an unknown number type, it should tell you that it's not supported, rather than doing the Pythonic thing of trying to use it until it fails with a poor error message. Multiple dispatch is very convenient to use in this case, but we need to specify the fallback function manually. This is what is implemented in this version of SpelledOut.jl See merge request #61
1 parent 1d5ff37 commit ef2d98f

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SpelledOut"
22
uuid = "4728c690-e668-4265-bc0d-51a8c0f93067"
33
authors = ["Jake W. Ireland <[email protected]> and contributors"]
4-
version = "1.2.3"
4+
version = "1.2.4"
55

66
[deps]
77
DecFP = "55939f99-70c6-5e9b-8bb0-5071ed7d61fd"

src/es.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function es_spell_large(_number)
9292
end
9393

9494

95-
function spelled_out_es(number; dict=:standard)
95+
function spelled_out_es(number::Union{Integer, Float64}; dict=:standard)
9696
if iszero(number)
9797
return "cero"
9898
end
@@ -135,3 +135,7 @@ end
135135

136136

137137

138+
# Fallback method if we do not know how to handle the input
139+
function spelled_out_es(number, dict = :standard)
140+
throw(error("Cannot parse type $(typeof(number)). Please make an issue."))
141+
end

src/pt.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function pt_spell_large( _number; portugal::Bool = false )
120120
return res
121121
end
122122

123-
function spelled_out_pt( number; portugal::Bool = false, dict::Symbol = :standard )
123+
function spelled_out_pt( number::Union{Integer, Float64}; portugal::Bool = false, dict::Symbol = :standard )
124124
if iszero( number )
125125
return "zero"
126126
end
@@ -156,3 +156,7 @@ function spelled_out_pt( number; portugal::Bool = false, dict::Symbol = :standar
156156
end
157157

158158

159+
# Fallback method if we do not know how to handle the input
160+
function spelled_out_pt(number; portugal::Bool = false, dict::Symbol = :standard)
161+
throw(error("Cannot parse type $(typeof(number)). Please make an issue."))
162+
end

src/ru.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
function spelled_out_ru(number::Number)
22

3+
4+
end
5+
6+
# Fallback method if we do not know how to handle the input
7+
function spelled_out_ru(number)
8+
throw(error("Cannot parse type $(typeof(number)). Please make an issue."))
39
end

0 commit comments

Comments
 (0)