Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A simple, tiny library for defining an Elixir@type whose values are one of a few options

License

NotificationsYou must be signed in to change notification settings

felt/union_typespec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple, tiny, compile time-only library for defining an Elixir@type whose valuesare one of a fixed set of options.

There are two ways to use it:

  1. Theunion_type andunion_typep macros, which replaces normal@type/@typep annotations with a nice,concise macro version of the type definition.
  2. UnionTypespec.union_type_ast/1, which produces an AST you canunquote withinthe usual@type definition.

Here's what those look like in practice:

defmoduleMyModuledoimportUnionTypespec,only:[union_type:1]@statuses[:read,:unread,:deleted]union_typestatus::@statuses@permissions[:view,:edit,:admin]@typepermission::unquote(UnionTypespec.union_type_ast(@permissions))@specget_permission()::permission()defget_permission,do:Enum.random(@permissions)@specget_status()::status()defget_status,do:Enum.random(@statuses)end

Installation

You can install the package from Hex by adding this to yourmix.exs file's dependencies:

defdepsdo[{:union_typespec,"~> 0.0.4",runtime:false},]end

About

A simple, tiny library for defining an Elixir@type whose values are one of a few options

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp