I had the `one_of` approach as my other alternative but figured adding
another function to Kernel (or elsewhere) may not be in favour. What do you
suggest I do next to progress this `one_of` idea as a poc?
Thanks too for the reduction, my attempts were making that far too
complicated!
On Saturday, May 16, 2020 at 3:29:27 PM UTC+8, José Valim wrote:
>
> Today you can do it like this:
>
> var = Enum.reduce(@list, &{:|, _. [&1, &2]}
> @type foo :: unquote(var)
>
> But it may be worth introducing something like you describe but it
> probably makes sense to do it via a construct, such as @type foo ::
> one_of(@var) that does the conversion for you. I think automatically
> converting the list can be confusing, because people may think that [:foo,
> :bar] implies a specific ordering, for example.
>
> I am just not sure of a good name. one_of may conflict with existing code.
>
> On Sat, May 16, 2020 at 6:25 AM Kip <[email protected] <javascript:>>
> wrote:
>
>> It's not uncommon to have domain overlap between lists of valid tokens
>> (used for validations) and type specs. For example:
>>
>> @standard_formats [
>> :standard,
>> :accounting,
>> :currency,
>> :percent
>> ]
>>
>> @currency_formats [
>> :currency,
>> :accounting,
>> :currency_long,
>> :currency_short
>> ]
>>
>> @currency_symbol [
>> :standard,
>> :iso
>> ]
>>
>> @type standard_formats :: :standard | :currency | :accounting | :short
>> | :long
>> @type currency_formats :: :currency_short | :currency_long |
>> :decimal_short | :decimal_long
>> @type currency_symbol :: :standard | :iso
>>
>> It would go good to remove one source of error by being able to allow
>> compile time use of a list as the subject of @typespec. For example:
>>
>> @type currency_symbol :: @currency_symbol # Any compile-time resolvable
>> list
>>
>> Of course a macro can be introduced to do this but its quite difficult to
>> achieve since it requires manual manipulation of AST.
>>
>> Proposal worth considering? Or consign to the history of my
>> less-than-helpful ideas :-)
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "elixir-lang-core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/elixir-lang-core/36f821aa-d718-48aa-a9e8-2f6d5e440632%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/elixir-lang-core/36f821aa-d718-48aa-a9e8-2f6d5e440632%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
You received this message because you are subscribed to the Google Groups
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/3577d145-b325-4c67-806c-d634df15ad5a%40googlegroups.com.