Base.insert!
— Methodinsert!(arr::Vector{T}, elem::T; before = nothing, after = nothing, strict::Bool = false)
Insert elem
into arr
either immediately before before
or immediately after after
. Specifying both keyword arguments before
and after
as well as neither is illegal - exactly one must be specified. The specified relative element must exist in the array.
If strict
is false, simple equality (==) is used, otherwise strict equality (===).
ExtraFun.decamelcase
— Methoddecamelcase(str; uppercase::Bool = false)
Remove camel-case and transform into lowercase or uppercase with underscore separators (e.g. "fooBarBaz" to "foobarbaz"). If uppercase
is true, the result will be uppercased, otherwise lowercased.
ExtraFun.iterable
— Methoditerable(x)
If x
is iterable (i.e. iterate(x)
exists), return x
. Otherwise, return an iterable container around x
, e.g. tuple(x)
. The result of this function will always be iterable.
ExtraFun.load
— Methodload(::Optional)
loads the Optional
's associated value from remote storage and caches it.
ExtraFun.xcopy
— Methodxcopy(tpl, kwargs...)
Extended Base.copy
method which allows setting a field directly rather than copying it from tpl
.
See also @xcopy
, xcopyargs
, xcopy_override
, xcopy_construct
.
Example
struct Foo{A}
a::A
end
xcopy(Foo{Int32}(24), a=42) # == Foo{Int32}(42)
ExtraFun.xcopy_construct
— Methodxcopy_construct(tpl, args...; kwargs...)
Constructs the actual copy. Useful for running additional initialization code or to add additional constructor arguments.
Example
struct Foo{T<:Real}
value::T
deduced::Float64
end
Foo(value::Real) = Foo(value, value / 2)
xcopy_construct(tpl::Foo, args...) = Foo(args[1], args[2]/2)
xcopy(Foo(24)) # == Foo(24, 12.0)
ExtraFun.xcopy_override
— Methodxcopy_override(tpl, ::FieldCopyOverride{S}) where S
Defines the copied value of field S
in tpl
. Defaults to Base.copy(getproperty(tpl, S))
.
See also xcopy
.
Example
```julia struct Foo value::Int end
struct Bar foo::Foo end
xcopy_override(bar::Bar, ::FieldCopyOverride{:foo}) = Foo(bar.foo.value + 1) xcopy(Bar(Foo(24))) # == Bar(Foo(25))
ExtraFun.xcopyargs
— Methodxcopyargs(ArgsT::Type, tpl; kwargs...)
Like xcopy
, except kwargs
must match fields of ArgsT
. A copy of tpl
will then be created like such: typeof(tpl)(argsobj)
where argsobj::ArgsT
is constructed through tpl
and kwargs
.
By default, the algorithm will attempt to retrieve an equally named field from tpl
to construct argsobj
with. This behavior can be overridden with xcopy_override
.
See also xcopy
, xcopy_override
, @xcopyoverride
, xcopy_construct
ExtraFun.@curry
— Macro@curry exprs...
Injects exprs
as the first arguments in every first-level method calls of the last argument. Like curry
, but does not generate an anonymous method instance that can be passed to other methods.
Example
logid = 42
@curry "Log " logid ": " begin
println(420)
println(69)
end
# prints "Log 42: 420"
# prints "Log 42: 69"
ExtraFun.@with
— Macro@with resources... block
Produces code like:
let resources...
try
block
finally
close.(resources)
end
end
This is useful for resources implementing Base.close
but no callbacked resource opener.
ExtraFun.@xcopy
— Macro@xcopy(T)
Convenience macro to define Base.copy(tpl::T; kwargs...) = xcopy(tpl, kwargs...)
See xcopy
, xcopyargs
, xcopy_override
ExtraFun.@xcopy_override
— Macro@xcopyoverride(T, S, expr)
Convenience macro to define xcopy_override(tpl::T, ::FieldCopyOverride{S}) = expr
.
See xcopy
, xcopy_override
Example
struct Foo
value::Int
end
@xcopy Foo
@xcopyoverride Foo :value tpl.value / 2
ExtraFun.@xcopyargs
— Macro@xcopyargs(T, A)
Convenience macro to define Base.copy(tpl::T; kwargs...) = xcopyargs(A, tpl, kwargs...)
See xcopy
, xcopyargs
, xcopy_override