Skip to content

Commit 0d3f74c

Browse files
Merge pull request #21 from ChrisRackauckas/fix-formatting
Apply JuliaFormatter to fix code formatting
2 parents f0b2633 + 2f1b835 commit 0d3f74c

5 files changed

Lines changed: 52 additions & 36 deletions

File tree

.JuliaFormatter.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
style = "sciml"
2+
format_markdown = true
3+
format_docstrings = true

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@
33
[![Build Status](https://github.com/chriselrod/FunctionWrappersWrappers.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/chriselrod/FunctionWrappersWrappers.jl/actions/workflows/CI.yml?query=branch%3Amain)
44
[![Coverage](https://codecov.io/gh/chriselrod/FunctionWrappersWrappers.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/chriselrod/FunctionWrappersWrappers.jl)
55

6-
76
If wrapping your functions once makes them better, why not try wrapping them twice?
8-

docs/make.jl

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
using FunctionWrappersWrappers
22
using Documenter
33

4-
DocMeta.setdocmeta!(FunctionWrappersWrappers, :DocTestSetup, :(using FunctionWrappersWrappers); recursive=true)
4+
DocMeta.setdocmeta!(FunctionWrappersWrappers, :DocTestSetup,
5+
:(using FunctionWrappersWrappers); recursive = true)
56

67
makedocs(;
7-
modules=[FunctionWrappersWrappers],
8-
authors="Chris Elrod <elrodc@gmail.com> and contributors",
9-
repo="https://github.com/chriselrod/FunctionWrappersWrappers.jl/blob/{commit}{path}#{line}",
10-
sitename="FunctionWrappersWrappers.jl",
11-
format=Documenter.HTML(;
12-
prettyurls=get(ENV, "CI", "false") == "true",
13-
canonical="https://chriselrod.github.io/FunctionWrappersWrappers.jl",
14-
assets=String[],
8+
modules = [FunctionWrappersWrappers],
9+
authors = "Chris Elrod <elrodc@gmail.com> and contributors",
10+
repo = "https://github.com/chriselrod/FunctionWrappersWrappers.jl/blob/{commit}{path}#{line}",
11+
sitename = "FunctionWrappersWrappers.jl",
12+
format = Documenter.HTML(;
13+
prettyurls = get(ENV, "CI", "false") == "true",
14+
canonical = "https://chriselrod.github.io/FunctionWrappersWrappers.jl",
15+
assets = String[]
1516
),
16-
pages=[
17+
pages = [
1718
"Home" => "index.md",
18-
],
19+
]
1920
)
2021

2122
deploydocs(;
22-
repo="github.com/chriselrod/FunctionWrappersWrappers.jl",
23-
devbranch="main",
23+
repo = "github.com/chriselrod/FunctionWrappersWrappers.jl",
24+
devbranch = "main"
2425
)

src/FunctionWrappersWrappers.jl

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,24 @@ import TruncatedStacktraces
55

66
export FunctionWrappersWrapper
77

8-
struct FunctionWrappersWrapper{FW,FB}
9-
fw::FW
8+
struct FunctionWrappersWrapper{FW, FB}
9+
fw::FW
1010
end
1111

1212
TruncatedStacktraces.@truncate_stacktrace FunctionWrappersWrapper
1313

14-
(fww::FunctionWrappersWrapper{FW,FB})(args::Vararg{Any,K}) where {FW,K,FB} = _call(fww.fw, args, fww)
14+
function (fww::FunctionWrappersWrapper{FW, FB})(args::Vararg{Any, K}) where {FW, K, FB}
15+
_call(fww.fw, args, fww)
16+
end
1517

16-
_call(fw::Tuple{FunctionWrappers.FunctionWrapper{R,A},Vararg}, arg::A, fww::FunctionWrappersWrapper) where {R,A} = first(fw)(arg...)
17-
_call(fw::Tuple{FunctionWrappers.FunctionWrapper{R,A1},Vararg}, arg::A2, fww::FunctionWrappersWrapper) where {R,A1,A2} = _call(Base.tail(fw), arg, fww)
18+
function _call(fw::Tuple{FunctionWrappers.FunctionWrapper{R, A}, Vararg},
19+
arg::A, fww::FunctionWrappersWrapper) where {R, A}
20+
first(fw)(arg...)
21+
end
22+
function _call(fw::Tuple{FunctionWrappers.FunctionWrapper{R, A1}, Vararg},
23+
arg::A2, fww::FunctionWrappersWrapper) where {R, A1, A2}
24+
_call(Base.tail(fw), arg, fww)
25+
end
1826

1927
const NO_FUNCTIONWRAPPER_FOUND_MESSAGE = "No matching function wrapper was found!"
2028

@@ -24,14 +32,20 @@ function Base.showerror(io::IO, e::NoFunctionWrapperFoundError)
2432
print(io, NO_FUNCTIONWRAPPER_FOUND_MESSAGE)
2533
end
2634

27-
_call(::Tuple{}, arg, fww::FunctionWrappersWrapper{<:Any,false}) = throw(NoFunctionWrapperFoundError())
28-
_call(::Tuple{}, arg, fww::FunctionWrappersWrapper{<:Any,true}) = first(fww.fw).obj[](arg...)
35+
function _call(::Tuple{}, arg, fww::FunctionWrappersWrapper{<:Any, false})
36+
throw(NoFunctionWrapperFoundError())
37+
end
38+
function _call(::Tuple{}, arg, fww::FunctionWrappersWrapper{<:Any, true})
39+
first(fww.fw).obj[](arg...)
40+
end
2941

30-
function FunctionWrappersWrapper(f::F, argtypes::Tuple{Vararg{Any,K}}, rettypes::Tuple{Vararg{DataType,K}}, fallback::Val{FB}=Val{false}()) where {F,K,FB}
31-
fwt = map(argtypes, rettypes) do A, R
32-
FunctionWrappers.FunctionWrapper{R,A}(f)
33-
end
34-
FunctionWrappersWrapper{typeof(fwt),FB}(fwt)
42+
function FunctionWrappersWrapper(
43+
f::F, argtypes::Tuple{Vararg{Any, K}}, rettypes::Tuple{Vararg{DataType, K}},
44+
fallback::Val{FB} = Val{false}()) where {F, K, FB}
45+
fwt = map(argtypes, rettypes) do A, R
46+
FunctionWrappers.FunctionWrapper{R, A}(f)
47+
end
48+
FunctionWrappersWrapper{typeof(fwt), FB}(fwt)
3549
end
3650

3751
end

test/runtests.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ using FunctionWrappersWrappers
22
using Test
33

44
@testset "FunctionWrappersWrappers.jl" begin
5-
6-
fwplus = FunctionWrappersWrapper(+, (Tuple{Float64,Float64}, Tuple{Int,Int}), (Float64,Int));
7-
@test fwplus(4.0, 8.0) === 12.0
8-
@test fwplus(4, 8) === 12
9-
10-
fwexp2 = FunctionWrappersWrapper(exp2, (Tuple{Float64}, Tuple{Float32}, Tuple{Int}), (Float64,Float32,Float64));
11-
@test fwexp2(4.0) === 16.0
12-
@test fwexp2(4f0) === 16f0
13-
@test fwexp2(4) === 16.0
5+
fwplus = FunctionWrappersWrapper(+, (Tuple{Float64, Float64}, Tuple{Int, Int}), (
6+
Float64, Int));
7+
@test fwplus(4.0, 8.0) === 12.0
8+
@test fwplus(4, 8) === 12
149

10+
fwexp2 = FunctionWrappersWrapper(
11+
exp2, (Tuple{Float64}, Tuple{Float32}, Tuple{Int}), (Float64, Float32, Float64));
12+
@test fwexp2(4.0) === 16.0
13+
@test fwexp2(4.0f0) === 16.0f0
14+
@test fwexp2(4) === 16.0
1515
end

0 commit comments

Comments
 (0)