From 91e70252e4a612637b672872b162ad006dfa638c Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sun, 20 Mar 2022 23:05:50 -0700 Subject: [PATCH] Move `@and_then` and `@or_else` to `TryExperimental` (#25) --- lib/TryExperimental/src/TryExperimental.jl | 6 ++++++ src/sugar.jl => lib/TryExperimental/src/sugars.jl | 0 src/Try.jl | 9 +-------- test/TryTests/src/test_tools.jl | 7 +++---- 4 files changed, 10 insertions(+), 12 deletions(-) rename src/sugar.jl => lib/TryExperimental/src/sugars.jl (100%) diff --git a/lib/TryExperimental/src/TryExperimental.jl b/lib/TryExperimental/src/TryExperimental.jl index 1709108..4b8ef20 100644 --- a/lib/TryExperimental/src/TryExperimental.jl +++ b/lib/TryExperimental/src/TryExperimental.jl @@ -38,6 +38,9 @@ abstract type EmptyError <: Exception end abstract type ClosedError <: Exception end # abstract type FullError <: Exception end +macro and_then end +macro or_else end + baremodule Causes function notimplemented end function empty end @@ -46,6 +49,7 @@ end # baremodule Cause module Internal +import ..TryExperimental: @and_then, @or_else using ..TryExperimental: TryExperimental, Causes using Try @@ -55,8 +59,10 @@ for n in names(TryExperimental; all = true) @eval import TryExperimental: $n end +using Base.Meta: isexpr using Base: IteratorEltype, HasEltype, IteratorSize, HasLength, HasShape +include("sugars.jl") include("causes.jl") include("base.jl") diff --git a/src/sugar.jl b/lib/TryExperimental/src/sugars.jl similarity index 100% rename from src/sugar.jl rename to lib/TryExperimental/src/sugars.jl diff --git a/src/Try.jl b/src/Try.jl index c18198d..a88d12f 100644 --- a/src/Try.jl +++ b/src/Try.jl @@ -57,9 +57,6 @@ end abstract type NotImplementedError <: Exception end -macro and_then end -macro or_else end - macro and_return end function var"@?" end @@ -68,7 +65,7 @@ function or_else end module Internal -import ..Try: @and_return, @?, @and_then, @or_else, @function +import ..Try: @and_return, @?, @function using ..Try: AbstractResult, ConcreteErr, @@ -81,8 +78,6 @@ using ..Try: Try using ..Try.InternalPrelude: _ConcreteResult, _IsOkError -using Base.Meta: isexpr - include("ExternalDocstrings.jl") using .ExternalDocstrings: @define_docstrings @@ -93,8 +88,6 @@ include("function.jl") include("branch.jl") -include("sugar.jl") - end # module Internal Internal.@define_docstrings diff --git a/test/TryTests/src/test_tools.jl b/test/TryTests/src/test_tools.jl index f0224d2..6385fff 100644 --- a/test/TryTests/src/test_tools.jl +++ b/test/TryTests/src/test_tools.jl @@ -3,6 +3,7 @@ module TestTools using Test using Try using TryExperimental +using TryExperimental: @and_then, @or_else function trygetnitems(xs) Try.@and_return trygetlength(xs) @@ -78,17 +79,15 @@ function demo_macro(xs) i = firstindex(xs) y = nothing while true - #! format: off - x = @Try.or_else(trygetindex(xs, i)) do _ + x = @or_else(trygetindex(xs, i)) do _ return :oob end - @Try.and_then(trygetindex(xs, Try.unwrap(x))) do z + @and_then(trygetindex(xs, Try.unwrap(x))) do z if z > 1 y = z break end end - #! format: on i += 1 end return y