Skip to content

Commit

Permalink
Merge pull request #24 from cstjean/functor-printing
Browse files Browse the repository at this point in the history
Functor printing
  • Loading branch information
cstjean authored Feb 25, 2023
2 parents 9ca187c + 00aee9e commit ba3fef0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "QuickTypes"
uuid = "ae2dfa86-617c-530c-b392-ef20fdad97bb"
version = "1.7.0"
version = "1.8.0"

[deps]
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
Expand All @@ -9,7 +9,7 @@ MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
[compat]
ConstructionBase = "1"
MacroTools = "0.5"
julia = "1.3"
julia = "1.7"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
13 changes: 11 additions & 2 deletions src/QuickTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ narrow_typeof(t::T) where {T} = T

# Helper for @qmutable/@qstruct
# narrow_types means that
function qexpansion(def, mutable, fully_parametric, narrow_types)
function qexpansion(def::Expr, mutable::Bool, fully_parametric::Bool, narrow_types::Bool)
if !@capture(def, typ_def_ <: parent_type_)
typ_def = def
parent_type = :Any
Expand Down Expand Up @@ -377,6 +377,15 @@ end
################################################################################
# @qfunctor

""" Abstract type for qfunctors. Was introduced to improve printing of QFunctor """
abstract type QFunctor <: Function end

Base.show(io::IO, mime::MIME"text/plain", qf::QFunctor) =
# Without this method, functors print like functions, i.e.
# (::Foo) (generic function with 1 methods)
# which is bothersome because the fields don't show up.
Base.@invoke(Base.show(io::typeof(io), mime::typeof(mime), qf::Any))

"""
```julia
@qfunctor function Action(verb::Symbol)(what)
Expand All @@ -402,7 +411,7 @@ macro qfunctor(fdef0)
fdef = A
else
fdef = fdef0
parenttype = :($Base.Function)
parenttype = :($QFunctor)
end
di = splitdef(fdef)
type_def = di[:name]
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ end

@qfunctor ParamAction{X}(a::X)(b::T) where T = (a, b, X, T)
@test ParamAction(1)(2.0) == (1, 2.0, Int, Float64)
@test string(ParamAction(1)) == "ParamAction{Int64}(1)"

io = IOBuffer();
show(io, MIME"text/plain"(), ParamAction(1))
@test String(take!(io)) == "ParamAction{Int64}(1)"

################################################################################
# @destruct
Expand Down

2 comments on commit ba3fef0

@cstjean
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/78525

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.8.0 -m "<description of version>" ba3fef04ad0447fe5e96003ef71f457ec2710206
git push origin v1.8.0

Please sign in to comment.