Skip to content

Commit cf6c542

Browse files
committed
Small improvements
1 parent a0e2635 commit cf6c542

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/prob_macro.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ macro prob_str(str)
88
end
99

1010
function get_exprs(str::String)
11-
ind = findfirst(isequal('|'), str)
12-
ind === nothing && throw("Invalid expression.")
13-
14-
str1 = str[1:(ind - 1)]
15-
str2 = str[(ind + 1):end]
11+
substrings = split(str, '|'; limit = 2)
12+
length(substrings) == 2 || error("Invalid expression.")
13+
str1, str2 = substrings
1614

1715
expr1 = Meta.parse("($str1,)")
1816
expr1 = Expr(:tuple, expr1.args...)
@@ -57,7 +55,7 @@ function probtype(ntl::NamedTuple{namesl}, ntr::NamedTuple{namesr}) where {names
5755
defaults = getdefaults(modelgen)
5856
valid_arg(arg) = isdefined(ntl, arg) || isdefined(ntr, arg) ||
5957
isdefined(defaults, arg) && getfield(defaults, arg) !== missing
60-
@assert all(valid_arg.(getargtypes(modelgen)))
58+
@assert all(valid_arg, getargtypes(modelgen))
6159
return Val(:likelihood), modelgen, vi
6260
else
6361
@assert isdefined(ntr, :model)
@@ -96,7 +94,7 @@ function probtype(
9694
a = get_arg(arg)
9795
return a !== nothing && a !== missing
9896
end
99-
valid_args = all(valid_arg.(args))
97+
valid_args = all(valid_arg, args)
10098

10199
# Uses the default values for model arguments not provided.
102100
# If no default value exists, use `nothing`.

0 commit comments

Comments
 (0)