# New alias for Dry::Struct#new

**URL:** <https://discourse.dry-rb.org/t/new-alias-for-dry-struct-new/366>\
**Category:** Ideas\
**Created:** [October 15, 2017, 6:26am UTC](https://discourse.dry-rb.org/t/new-alias-for-dry-struct-new/366 "2017-10-15T06:26:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![citizen428](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/citizen428/32/144_2.png) [@citizen428](https://discourse.dry-rb.org/u/citizen428)\
**Post date:** [October 15, 2017, 6:26am UTC](https://discourse.dry-rb.org/t/new-alias-for-dry-struct-new/366/1 "2017-10-15T06:26:27Z")

</div>

I experimented with aliasing `#new` to `|` since it resembles the way Elm records and Elixir maps are updated:

```ruby
p = Person[name: "Test", age: 42]
#=> #<Person name="Test" age=42>
p | { age: 43 }
#=> #<Person name="Test" age=43>

```

I kinda like it, what do you think?

---

<div class="post-metadata">

**Author:** ![timriley](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/timriley/32/25_2.png) [@timriley](https://discourse.dry-rb.org/u/timriley)\
**Post date:** [October 16, 2017, 3:57am UTC](https://discourse.dry-rb.org/t/new-alias-for-dry-struct-new/366/2 "2017-10-16T03:57:35Z")

</div>

I have to say, this is impressively concise! But I feel it’s perhaps a little too… not-idiomatic for the Ruby world (even for us!). I feel that this could also be potentially confusing given we’re already using `|` for logical operations in other dry-\* gems (dry-validation and dry-logic).

I’m interested to hear: how often do you think you’d find yourself wanting to use `#new`, and for what reasons? It’s not something I’ve done all that much of in the apps I’m building, at least.

---

<div class="post-metadata">

**Author:** ![citizen428](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/citizen428/32/144_2.png) [@citizen428](https://discourse.dry-rb.org/u/citizen428)\
**Post date:** [October 16, 2017, 4:43am UTC](https://discourse.dry-rb.org/t/new-alias-for-dry-struct-new/366/3 "2017-10-16T04:43:43Z")

</div>

I did wonder about this, but then it’s actually somewhat in line with how it works for arrays:

```ruby
[1,2,3] | [4]
#=> [1, 2, 3, 4]

```

For key-value-pairs I think it’s reasonable that elements with the same key would overwrite the existing value.

But you may have a good point, it’s not really that important, since for the rare cases one would want to do this `new` is perfectly sufficient. I guess this was all based on some ideas re state management I wanted to try to try to borrow from Elm and then a concise syntax like this would be nice.
