Skip to content

cursorinsight/Patterns.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Patterns.jl

CI

Patterns.jl is a Julia package that provides support for pattern matching.

Installation

Patterns.jl can be installed after adding Cursor Insight's own registry to the Julia environment:

julia> ]
pkg> registry add https://github.com/cursorinsight/julia-registry
     Cloning registry from "https://github.com/cursorinsight/julia-registry"
       Added registry `CursorInsightJuliaRegistry` to
       `~/.julia/registries/CursorInsightJuliaRegistry`

pkg> add Patterns

Usage

Load the package via

using Patterns

This exports @pattern macro.

You can create functions with pattern in the signature using @pattern:

@pattern function f(:one)
    return 1
end

You can also use multiple symbols and other parameters in the signature:

@pattern function f(::Type{String}, :one)
    return "1"
end

Or you can call a function with pattern. NOTE: all the Symbols are replaced in a function call.

@assert f(String, :one) == string(f(:one))

Advanced example

Create fixtures that provide data for your tests.

@pattern function fixture(:numbers, :odd)
    return [1, 7, 11]
end

@pattern function fixture(:numbers, :even)
    return [2, 8, 12]
end

To execute the following test:

@test any(!myiseven, fixture(:numbers, :odd))
@test all( myiseven, fixture(:numbers, :even))

About

Pattern matching in Julia

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages