Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If Array.append has not mutable arguments partially applied then the lambda can be removed

Tags:

arrays

lambda

f#

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?

like image 839
ceth Avatar asked Nov 24 '15 16:11

ceth


People also ask

How to append an element to the end of an array?

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.

What is append () method in NumPy?

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

What happens when you mutate a default argument in a 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.

What is the difference between mutable and immutable types in Python?

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.


1 Answers

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
like image 200
Bartek Kobyłecki Avatar answered Nov 16 '22 10:11

Bartek Kobyłecki