I have Array of Array of strings. I need to flatten them and I use:
Array.fold (fun acc el -> Array.append acc el) [||] arr2d
Lint says me that:
"If Array.append has not mutable arguments partially applied then the lambda can be removed"
What does it mean? How can I remove lambda?
Python append () function enables us to add an element or an array to the end of another array. That is, the specified element gets appended to the end of the input array. The append () function has a different structure according to the variants of Python array mentioned above.
Variant 3: Python append () method with NumPy array The NumPy module can be used to create an array and manipulate the data against various mathematical functions. Syntax: Python numpy.append () function
This can inadvertently create hidden shared state, if you use a mutable default argument and mutate it at some point. This means that the mutated argument is now the default for all future calls to the function as well. Take the following code as an example. Every call to the function shares the same list.
In short, Python has both mutable and immutable types. The difference being: immutables can’t be modified. For eg: Tuple is an immutable type. If we define a tuple like this: An immutable type can never be modified.
Any lambda function in that form (fun x -> f x)
can be expressed as f
. Holding immutable condition.
In your code you have fun acc el -> Array.append acc el
which has the same type and does the same as Array.append
, so you can shorten it to:
Array.fold Array.append [||] arr2d
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With