#2449 it-block enhancement

SlimerDude Mon 31 Aug 2015

A quick idea for it-blocks...

They're great for creating simple little functions, such as:

nums := [1, 2, 3]
num  := nums.find { it.div(2) == 1 }

But often, especially when using Obj lists and maps from other frameworks (such as web or afConcurrent), you loose type information, meaning you have to supply the full function signature.

nums := (Obj[]) [1, 2, 3]
num  := nums.find |Int int -> Bool| { int.div(2) == 1 }

Whilst correct, it's also pain to type. So how about being able to supply a type for it, so the above could be re-written as:

nums := (Obj[]) [1, 2, 3]
num  := nums.find |Int| { it.div(2) == 1 }

The idea being you leave the function body alone as is, and just add |Type| to the beginning.

Jeremy Criquet Tue 1 Sep 2015

I like this idea.

brian Tue 1 Sep 2015

Its a good idea, but not sure I really love it. It is a fairly big complication in type signatures (which are already complicated), but only saves a few chars versus using a named parameter. Plus I actually prefer to cast the list to its correct type before calling something like find.

Login or Signup to reply.