API Reference
Thinkers.Thunk — TypeThunk(callable, args...; kwargs...)Hold a callable and its arguments for lazy evaluation. Use reify! to evaluate.
Examples
julia> using Thinkers
julia> a = Thunk(x -> 3x, 4);
julia> reify!(a);
julia> getresult(a)
Some(12)
julia> b = Thunk(+, 4, 5);
julia> reify!(b);
julia> getresult(b)
Some(9)
julia> c = Thunk(sleep, 1);
julia> getresult(c) # `c` has not been evaluated
julia> reify!(c); # `c` has been evaluated
julia> getresult(c)
Some(nothing)
julia> f(args...; kwargs...) = collect(kwargs);
julia> d = Thunk(f, 1, 2, 3; x=1.0, y=4, z="5");
julia> reify!(d);
julia> getresult(d)
Some(Pair{Symbol, Any}[:x => 1.0, :y => 4, :z => "5"])
julia> e = Thunk(sin, "1"); # Catch errors
julia> reify!(e);
julia> haserred(e)
trueMissing docstring for Thunk(::Thunk). Check Documenter's build log for details.
Thinkers.ErrorInfo — TypeCapture errors and stack traces from a running Thunk.
Thinkers.isreified — Functionisreified(thunk::Thunk)Determine whether thunk has been reified.
Thinkers.haserred — Functionhaserred(thunk::Thunk)Check if thunk produced an error when reified.
Thinkers.getresult — Functiongetresult(thunk::Thunk)Get the result of a Thunk. If thunk has not been reified, return nothing, else return a Some-wrapped result.
Thinkers.unwrapresult — Functionunwrapresult(think::Think)Unwrap the retrieved result of a think object.
This function extracts the result of a Think object from its Some container. If the Think object has not been reified (i.e., reify! has not been called) or is still running, it throws an error.
Thinkers.reify! — Functionreify!(thunk::Thunk)Reify a Thunk.
Calculate the value of the expression by recursively evaluating each argument and keyword of the Thunk, and then evaluating the Thunk's callable with the evaluated arguments.
If called again, this function will recompute everything from scratch.
Some functions that the Think object wraps may modify their arguments or depend on external state (i.e., they are not pure functions), which could lead to different results upon re-evaluation.
Thinkers.setargs! — Functionsetargs!(think::Think, args...; kwargs...)Change the arguments of a Think, after it has been created but before it has been evaluated.
Thinkers.reset! — Functionreset!(think::Think)Reset the computation result of the think object.
Please be aware that reset! does not guarantee that a Think object will behave exactly as if it has never been evaluated. Some functions that the Think object wraps may modify their arguments or depend on external state (i.e., they are not pure functions), which could lead to different results upon re-evaluation.