Open rauschma opened 6 years ago
/**
l
, remove all occurrences of the value ~value
~with_
.
*/
The replace comment retained the remove from the previous example. I think it is : replace all occurrences...Guys, could you help to understand the phrase: "Note that concatenating lists is comparatively slow, because you must prepend each element of the first operand to the second operand..". Is that makes sense how it slow or quick the operation, if it will become the common js operation after the OCaml to JS compilation? I mean that we do concatenation in js by the Array.concat, and is that exactly this method we will use in compiled to js code?
@geraldodev Could you put lines with three backticks before and after your code, like this:
this is the code
Currently your comments are hard to read and understand (GitHub lets you edit existing comments).
@eugrdn I take it you understand why the operation is slow?
If you concatenate often, it’s better to switch to arrays. ReasonML also lets you convert between lists and arrays, so you can use each of them for what they do well, as described in the following table: http://reasonmlhub.com/exploring-reasonml/ch_arrays.html#lists-vs.arrays
let rec getElementAt = (~index: int, l: list('a)) =>
switch l {
| [] => None
| [head, ..._] when index <= 0 => Some(head)
| [head, ...tail] => getElementAt(~index=index-1, tail)
};
Js.log(getElementAt(-7, [5,6,7]));
//gives 5
Isn't the above operation should also result in None
? Then the condition should be index == 0
.
Typo at:
type mylist('a) =
| Nil;
| Cons('a, mylist('a))
The semi-colon should be on the last line, not after Nil.
No need rec on summarize that uses fold_left