# Can a function tell if an argument is in an enum or otherwise get the base type?

**URL:** <https://discourse.julialang.org/t/can-a-function-tell-if-an-argument-is-in-an-enum-or-otherwise-get-the-base-type/26332>\
**Category:** General Usage\
**Created:** [July 14, 2019, 1:49am UTC](https://discourse.julialang.org/t/can-a-function-tell-if-an-argument-is-in-an-enum-or-otherwise-get-the-base-type/26332 "2019-07-14T01:49:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tuckermcclure](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tuckermcclure/32/1187_2.png) [@tuckermcclure](https://discourse.julialang.org/u/tuckermcclure)\
**Post date:** [July 14, 2019, 1:49am UTC](https://discourse.julialang.org/t/can-a-function-tell-if-an-argument-is-in-an-enum-or-otherwise-get-the-base-type/26332/1 "2019-07-14T01:49:23Z")

</div>

I have a generic function that logs some data into a binary file for a user. Naturally, I need to know how many bits the type needs. This is easy to do for most types. However, I’m unclear on what to do when the user passes in an enum. I expect that I’ll need to call `Base.Enums.basetype` on the data in order to determine the bits necessary for logging it, but without knowing if it’s an enum already, how would I know I need to call that? I think I need an `isenum` function or something.

For most other types, I call `eltype` to return something like Float64, Int8, etc., but `eltype` returns `Any` for an enum.

Any ideas?

---

<div class="post-metadata">

**Author:** ![tuckermcclure](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tuckermcclure/32/1187_2.png) [@tuckermcclure](https://discourse.julialang.org/u/tuckermcclure)\
**Post date:** [July 14, 2019, 4:51am UTC](https://discourse.julialang.org/t/can-a-function-tell-if-an-argument-is-in-an-enum-or-otherwise-get-the-base-type/26332/2 "2019-07-14T04:51:19Z")

</div>

Oops, this is easy. I missed the existence of the Enum abstract type. I found it via `macroexpand` on an `@enum` macro. What I need is:

`typeof(argument) <: Enum`

or via multiple dispatch:

```julia
function log(..., data::T) where {T <: Enum}
   log(..., Base.Enums.basetype(T)(data))
end

```

to get down to the primitive underlying the enum.
