Base.insert!Method

insert!(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.decamelcaseMethod

decamelcase(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.iterableMethod

iterable(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.loadMethod

load(::Optional) loads the Optional's associated value from remote storage and caches it.

ExtraFun.xcopy_constructMethod

xcopy_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_overrideMethod

xcopy_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.xcopyargsMethod

xcopyargs(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.@curryMacro

@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.@withMacro

@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_overrideMacro

@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