Skip to content

Commit

Permalink
Add lambda function
Browse files Browse the repository at this point in the history
  • Loading branch information
danlooo committed Sep 12, 2024
1 parent 3010414 commit ba4fe74
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/OpenEOClient.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export
compute_result,
connect,
DataCube,
value,
describe_collection,
to_band,
list_collections,
Expand Down
18 changes: 16 additions & 2 deletions src/ProcessGraph.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using OrderedCollections

function flatten!(g::AbstractProcessCall, root_id, nodes=OrderedSet{ProcessCall}())
function flatten!(g::AbstractProcessCall, root_id, nodes=OrderedSet{AbstractProcessCall}())
has_parameter = x -> ProcessCallParameter in typeof.(values(x.arguments))
arguments_nodes = filter(((k, v),) -> v isa ProcessCall && !has_parameter(v), g.arguments)

Expand Down Expand Up @@ -52,6 +52,8 @@ Base.getindex(g::ProcessGraph, i) = Base.getindex(g.process_graph, i)
Base.length(g::ProcessGraph) = Base.length(g.process_graph)
print_json(g::ProcessGraph) = g |> JSON3.write |> JSON3.pretty

ProcessGraph(value::ProcessCallParameter) = ProcessGraph(value * 1) # allow identity ProcessGraph

"""
Create a ProcessGraph to reduce dimesnions
"""
Expand Down Expand Up @@ -95,4 +97,16 @@ end
function compute_result(connection::AuthorizedCredentials, json_graph_path::String, kw...)
process_graph = JSON3.read(json_graph_path) |> Dict
return compute_result(connection, process_graph, kw...)
end
end


#
# Build a ProcessGraph like a lambda function
#

Base.isequal(x::ProcessCall, y::ProcessCall) = x.id == y.id # required to create OrderedDict for ProcessGraph

Base.log(x::AbstractProcessCall, base::Number) = ProcessCall("log", Dict(:x => x, :base => base))
Base.:(*)(x::AbstractProcessCall, y::Number) = ProcessCall("multiply", Dict(:x => x, :y => y))
Base.:(*)(x::Number, y::AbstractProcessCall) = ProcessCall("multiply", Dict(:x => x, :y => y))
Base.:(==)(x::AbstractProcessCall, y) = ProcessCall("eq", Dict(:x => x, :y => y))
5 changes: 5 additions & 0 deletions src/Processes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ struct ProcessCallParameter <: AbstractProcessCall
from_parameter::String
end

"""
Placeholder to define process graphs e.g. lambda functions
"""
const value = ProcessCallParameter("value")

mutable struct ProcessCall <: AbstractProcessCall
const id::String
const process_id::String
Expand Down

0 comments on commit ba4fe74

Please sign in to comment.