There are smarter ways to deal with data structures in the functional setting than copying the entire structure over and over again.
See https://en.wikipedia.org/wiki/Purely_functional_data_structu... and Okasaki’s book Purely Functional Data Structures.