MLStyle.jl
MLStyle.jl copied to clipboard
Julia functional programming infrastructures and metaprogramming facilities
MLStyle.jl
Providing intuitive, fast, consistent and extensible functional programming infrastructures, and metaprogramming facilities.
Check everything in the documentation website.
Preview
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
.
Benchmarks
Arrays
Tuples
Data Types
Extracting Struct Definitions
Misc
An Example from Match.jl Documentation
Acknowledgements
Thanks to all individuals referred in Acknowledgements!