Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neutral additive element #437

Open
jonas-schulze opened this issue Nov 11, 2022 · 2 comments
Open

Neutral additive element #437

jonas-schulze opened this issue Nov 11, 2022 · 2 comments

Comments

@jonas-schulze
Copy link

Problem description

I would like to have an optional layer in the background, to which I then add some other layers on top. The manual states that mapping() is the one-element, but what is the zero-element here?

if draw_background
    plt = ...
else
    plt = zero(Layer) # doesn't exist (yet)
end
plt += ...

Proposed solution

Define zero(Layer) or AoG.zero() or similar. While being at it, one may also define one(Layer) or oneunit(Layer) or AoG.one() or similar.

@jkrumbiegel
Copy link
Member

I think what you want is Layers([]):

julia> Layers([]) + mapping(:x, :y)
Layers with 1 elements:
  Layer 1
    transformation: identity
    data: Nothing
    positional:
      1: x
      2: y
    named:


julia> Layers([]) * mapping(:x, :y)
Layers with 0 elements:

@jonas-schulze
Copy link
Author

Yes, that's the behavior I was looking for! But Layers([]) doesn't feel intuitive to me (I don't remember interacting with it before), I will likely forget about it again. What do you think about giving the other names I suggested?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants