Open michaellilltokiwa opened 2 years ago
I have added a page on destructuring to the design pages. This is still incomplete, but a point to collect ideas.
Using infix ||>
helps a bit here:
ex =>
[(1,"one"),(2, "two")]
.for_each (a -> a ||> (num, str) -> say "$num $str")
but partial application does not work yet, this code
ex =>
[(1,"one"),(2, "two")]
.for_each ||>((num, str) -> say "$num $str")
results in an error
> ./build//bin/fz destr.fz
/home/fridi/fuzion/clean/fuzion.1/destr.fz:3:20: error 1: No type information can be inferred from a lambda expression
.for_each ||>((n,s) -> say "$n $s")
A lambda expression can only be used if assigned to a field or argument of type 'Function'
with argument count of the lambda expression equal to the number of type parameters of the type. The type of the
assigned field must be given explicitly.
To solve this, declare an explicit type for the target field, e.g., 'f (i32, i32) -> bool := x, y -> x > y'.
one error.
When using tuples I find we often want to de-structure them in lambdas:
I think a shorter syntax like this could be handy: