Named tuples are
immutable, just like tuples so their contents cannot be changed.
However a nice solution to the copying verbosity problem would
be a copy_with
method (groovy had this for it’s @Immutable
classes and it worked well). For example:
tuple = {x: 3, y: 4}
tuple2 = tuple.copy_with(x: 5)
tuple2 # => {x: 5, y: 4}
--
You received this message because you are subscribed to the Google Groups "Crystal" group.
To unsubscribe from this group and stop receiving emails from it, send an email to crystal-lang...@googlegroups.com.
To post to this group, send email to crysta...@googlegroups.com.
Visit this group at https://groups.google.com/group/crystal-lang.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/039136fb-f310-4555-9192-d0b06d545085%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/c6a9b70e-5fce-8f12-e1d5-01fa8566641b%40rx14.co.uk.
For more options, visit https://groups.google.com/d/optout.
Because they’re stored on the stack. They’re immutable like every other struct.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/29b307c5-9293-16df-06e4-5566993cdbdf%40rx14.co.uk.
For more options, visit https://groups.google.com/d/optout.
I realise, however keeping the “structs must be immutable” perception alive, we avoid a bunch of problems with people not understanding structs later down the line. Even the documentation suggests that you make structs immutable:

Of course, this is
different for lib
structs.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/CAAvdMO-nL7jsAEgAoO21FvGsT8Jfr5C%3D0f4Xn8K_N%2Brs43MPbg%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to crystal-lang+unsubscribe@googlegroups.com.
To post to this group, send email to crysta...@googlegroups.com.
Visit this group at https://groups.google.com/group/crystal-lang.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/b32c4de5-3ee1-4ebb-a89d-661232b78ca7%40googlegroups.com.
I realise, however keeping the “structs must be immutable” perception alive, we avoid a bunch of problems with people not understanding structs later down the line. Even the documentation suggests that you make structs immutable:
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/b32c4de5-3ee1-4ebb-a89d-661232b78ca7%40googlegroups.com.