On Wed, 27 May 2015, xificurC wrote:
> Hi, I just started playing around with Yeti. On the first glance it's very nice, but I'm having
> issues doing java interop in a nice fashion. Let's say I have a list of java.lang.Objects (or any
> other java objects) and I want to filter this list, I first try
>
> filter do x: x#toString() == 'foo' done my_list
>
> This (as the tutorial states) doesn't work as for java objects often types need to be declared. So
> next I try
>
> filter do x is ~java.lang.Object -> boolean: x#toString() == 'foo' done my_list
>
> but that doesn't work either, I get a `bad argument: is' error. Can anonymous functions not be
> type annotated? I end up having to write
>
> my_filter x is ~java.lang.Object -> boolean = x#toString() == 'foo';
> filter my_filter my_list
>
> This is rather verbose. Is there any shorter way to do this?
You can write:
filter do x: (x is ~Object)#toString() == 'foo' done my_list;
or:
filter ((== 'foo') . string) my_list
or:
my_list |> map string |> filter (== 'foo')
> Another example - map a method over a list. Yeti has nice syntax so that you can write
>
> map (.foo) my_list
>
> for a list of structs that have a foo field. I don't see an equivalently nice solution to e.g.
> calling a java method like
>
> map (#foo()) my_list
>
> I end up writing
>
> my_fun x is ~java.foo.bar -> string = x#foo();
> map my_fun my_list
>
> Am I missing something? Any tips appreciated. I really like ML and would love to play around with
> Yeti, but one needs to use java libs extensively anyway and I'd need to clean up the interop a
> bit.
Here shortest would be about the same as above:
map (_ x = (x is ~java.foo.bar)#foo()) my_list;