Skip to content

Why ReadonlyXyz? #1609

Answered by mlegenhausen
edalex-ian asked this question in Q&A
Oct 28, 2021 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

Me again 😅

But I was under the impression that the non-ReadonlyXyz type classes were following the immutable paradigm

This only holds if you use fp-ts functions for data manipulations, but not for the functions that are defined on the non-readonly interfaces. An Array still has a push function which will mutate the array. On an ReadonlyArray the push function is not defined at all. So using the Readonly variants gives you simply more type safety, but with a "cost" that you need to explicitly convert to a mutable array when e. g. calling APIs that expects a mutable data structure.

In fp-ts@3 the mutable versions of Array, Record, NonEmptyArray and Map will be deprecated and will only con…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@edalex-ian
Comment options

@mlegenhausen
Comment options

@edalex-ian
Comment options

Answer selected by edalex-ian
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants