Skip to content

mossr/Optionals.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Optionals.jl

Light-weight Optional{T} types in Julia. Inspired by the Option type in Scala.

The Optional{T} is a simple alias for:

const Optional{T} = Union{T, Missing}

Installation

] add https://github.com/mossr/Optionals.jl

Usage

using Optionals

Example: Reassignment

let x::Optional{Int} = 10
    x = missing # works!
end
let x::Int = 10
    x = missing # errors!
end

Example: isthere

function example(input::Optional{Int})
    if isthere(input)
        println("The input $input is not missing!")
    else
        println("Input is missing.")
    end
end
julia> example(123)
The input 123 is not missing!

julia> example(missing)
Input is missing.

As see test_optional_customers.jl for a more detailed example.

About

Light-weight Optional{T} type in Julia

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages