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
It would be nice to have a Foldable typeclass similar to Haskell. Then things such as the following would work:
function sum
Foldable f => Integer ::= xs::f Integer { return foldl(\x::Integer y::Integer -> x + y, 0, xs); }
local aSet::Set<Integer> = ...
local aList::[Integer] = ...
local setSum::Integer = sum(aSet);
local listSum::Integer = sum(aList);
In my case, I was hoping for something like flatMap (foldMap in Haskell) to work on Set<a>, but that is specialized to lists only, so I had to write something like:
function foldMapSet
Monoid m => m ::= f::(m ::= a) s::set:Set<a> {
return flatMap(f, set:toList(s));
}
The text was updated successfully, but these errors were encountered:
It would be nice to have a Foldable typeclass similar to Haskell. Then things such as the following would work:
In my case, I was hoping for something like
flatMap
(foldMap
in Haskell) to work onSet<a>
, but that is specialized to lists only, so I had to write something like:The text was updated successfully, but these errors were encountered: