Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mainshayne233/union_type
https://github.com/mainshayne233/union_type
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/mainshayne233/union_type
- Owner: MainShayne233
- Created: 2019-08-29T15:42:57.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-08-29T23:54:14.000Z (about 5 years ago)
- Last Synced: 2024-10-30T16:58:30.339Z (19 days ago)
- Language: Elixir
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# UnionType
Define union types in Elixir!
## Example
```elixir
defmodule UserEnum do
use UnionTypeunion_type do
customer(name)
admin(name)
contractor(name, company)
guest()
end
enddefmodule App do
require UserEnumdef greet(UserEnum.guest()) do
"howdy guest!"
enddef greet(UserEnum.customer(name)) do
"howdy #{name}!"
end
def greet(UserEnum.admin(name)) do
"howdy #{name}! You are an admin!"
enddef greet(UserEnum.contractor(name, company)) do
"howdy #{name}! You are a contractor for #{company}"
end
endiex(18)> require UserEnum
UserEnumiex(20)> App.greet(UserEnum.guest())
"howdy guest!"iex(21)> App.greet(UserEnum.customer("John"))
"howdy John!"iex(22)> App.greet(UserEnum.admin("Linda"))
"howdy Linda! You are an admin!"iex(23)> App.greet(UserEnum.contractor("Erin", "MainTech"))
"howdy Erin! You are a contractor for MainTech"
```