Guidewire Gosu blocks

141 views Asked by At

Can someone explain why does when calling function test() and passing block to it, code understands that parameter of that block is type of Account, but when calling the same block test1() and passing another block to it the code won`t compile and it considers parameter of the block as block.case1 It will only work when setting parameter type.case2

I`m working with Policy Center v10, GW studio 5.0.4

var account = Account.finder.findAccountByAccountNumber("2251253246")

public function test(bl: block(Account): String) {
  print(bl(account))
}

var test1: block(block(Account): String) = \ bl: block(Account): String -> {
  print(bl(account))
}

test(\a-> a.AccountNumber)
test1(\a -> a.AccountNumber)
1

There are 1 answers

4
Gwisard On

It's actually very simple but deceiving at the same time.

The correct execution in your case would be as follows:

test(\a-> a.AccountNumber)
test1(\a : Account -> a.AccountNumber)

Your test() method accepts a block of param Account and return type of String. Your test1 block actually accepts as a parameter another block (of param Account and return type of String). Neither the method nor the outer block test1 returns anything.

So in the method test you aren't binding the block execution to a variable until inside the method. While in my example of how to execute the other block test1 I'm binding the account variable to the other block at the point of it's definition. Subtle but difference.

Having said that I'm not sure what problem you are really trying to solve here or what you are trying to achieve here.