Skip to content

Commit

Permalink
feat: add hasname function
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Nov 21, 2023
1 parent 064d9f0 commit 5b6e191
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ScalarSymbolic
ArraySymbolic
NotSymbolic
symbolic_type
hasname
getname
```

Expand Down
2 changes: 1 addition & 1 deletion src/SymbolicIndexingInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module SymbolicIndexingInterface

using Requires

export ScalarSymbolic, ArraySymbolic, NotSymbolic, symbolic_type , getname
export ScalarSymbolic, ArraySymbolic, NotSymbolic, symbolic_type, hasname, getname
include("trait.jl")

export is_variable, variable_index, variable_symbols, is_parameter, parameter_index,
Expand Down
9 changes: 9 additions & 0 deletions src/trait.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ symbolic_type(x) = symbolic_type(typeof(x))
symbolic_type(::Type) = NotSymbolic()
symbolic_type(::Type{Symbol}) = ScalarSymbolic()

Check warning on line 41 in src/trait.jl

View check run for this annotation

Codecov / codecov/patch

src/trait.jl#L39-L41

Added lines #L39 - L41 were not covered by tests

"""
hasname(x)
Check whether the given symbolic variable (for which `symbolic_type(x) != NotSymbolic()`) has a valid name as per `getname`.
"""
function hasname end

hasname(::Symbol) = true
hasname(::Any) = false

Check warning on line 51 in src/trait.jl

View check run for this annotation

Codecov / codecov/patch

src/trait.jl#L50-L51

Added lines #L50 - L51 were not covered by tests

"""
getname(x)::Symbol
Expand Down

0 comments on commit 5b6e191

Please sign in to comment.