You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
List.member needle (List.repeat n a)-->(n >=1)-- if determined True, only right&&(a == needle)-- if determined equal, only left-- and if both are determined True, return TrueList.any f needle (List.repeat n a)-->(n >=1)-- if determined True, only right&&(f a)List.all f needle (List.repeat n a)-->(n <=0)-- if determined True, only right||(f a)List.head (List.repeat n a)-- same with minimum, maximum-->if n <=0then -- if determined True, only elseNothingelseJust a
List.filter f (List.repeat n a)-->if f a thenList.repeat n a
else[]List.sum (List.repeat n a)--> (Basics.max 0 n) * aList.product (List.repeat n a)--> a ^ (Basics.max 0 n)List.reverse (List.repeat n a)-- same with sort, sortBy f, sortWith f--> List.repeat n a
for Array:
Array.get i (Array.repeat n a)-->if i >=0&& i < n thenJust a
elseNothingArray.filter f (Array.repeat n a)-->if f a thenArray.repeat n a
else[]
likely controversial
List.unzip (List.repeat n ( a, b ))--> ( List.repeat n a, List.repeat n b )
because if n is not simple, logic gets unnecessarily duplicated.
List.filterMap f (List.repeat n a)--> Maybe.withDefault [] (Maybe.map (List.repeat n) (f a))
because while it's technically simpler logic-wise and much more performant
the resulting code looks ugly (to me).
The text was updated successfully, but these errors were encountered:
The List.reverse one just makes a lot of sense in particular 👍
There are however a few ones that I think we probably shouldn't do, and those are the ones where we end up repeat n or f or a. While it looks good in small examples like these, these could be large expressions, and you end up with the code duplication (just like you mentioned for List.unzip) which then makes maintenance potentially harder.
for
Array
:likely controversial
because if
n
is not simple, logic gets unnecessarily duplicated.because while it's technically simpler logic-wise and much more performant
the resulting code looks ugly (to me).
The text was updated successfully, but these errors were encountered: