Providing intuitive, fast, consistent and extensible functional programming infrastructures, and metaprogramming facilities.
Check everything in the documentation website.
using MLStyle
@data Shape begin # Define an algebraic data type Shape
Rock
Paper
Scissors
end
# Determine who wins a game of rock paper scissors with pattern matching
play(a::Shape, b::Shape) = @match (a, b) begin
(Paper, Rock) => "Paper Wins!";
(Rock, Scissors) => "Rock Wins!";
(Scissors, Paper) => "Scissors Wins!";
(a, b) => a == b ? "Tie!" : play(b, a)
end
P.S: When preferring Base.@enum
than MLStyle.@data
, you need this to pattern match on Julia Base.@enum
.
Thanks to all individuals referred in Acknowledgements!