Skip to content
This repository has been archived by the owner on Jan 7, 2024. It is now read-only.

gdziadkiewicz/ValueDispatch.jl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Value Dispatch

Windows: Build status

Linux, IOS: Build Status

Function dispatch on value instead of type. Quite similar to Clojure's multimethods.

Behold:

@dispatch fizzbuzz(n::Int) = (n % 3 == 0, n % 5 == 0)

@on (true,true)  fizzbuzz(n) = "fizzbuzz"
@on (true,false) fizzbuzz(n) = "fizz"
@on (false,true) fizzbuzz(n) = "buzz"
@on :default     fizzbuzz(n) = n

for i in 1:15
    println(fizzbuzz(i))
end
# 1
# 2
# fizz
# 4
# buzz
# fizz
# 7
# 8
# fizz
# buzz
# 11
# fizz
# 13
# 14
# fizzbuzz

About

Function dispatch on values

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Julia 100.0%