# Function expression in when

**URL:** <https://discuss.kotlinlang.org/t/function-expression-in-when/63>\
**Category:** Uncategorized\
**Created:** [October 24, 2015, 8:47am UTC](https://discuss.kotlinlang.org/t/function-expression-in-when/63 "2015-10-24T08:47:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lakedaemon](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/lakedaemon/32/1421_2.png) [@Lakedaemon](https://discuss.kotlinlang.org/u/Lakedaemon)\
**Post date:** [October 24, 2015, 8:47am UTC](https://discuss.kotlinlang.org/t/function-expression-in-when/63/1 "2015-10-24T08:47:16Z")

</div>

I have a function that compiles in Kotlin 1.0.0 Beta if I write it like this&nbsp;&nbsp; {code} fun operation(int:Int) = when (int) { &nbsp;&nbsp;0-\> { &nbsp;&nbsp;val f = fun Int.() :Boolean { return true} &nbsp;&nbsp;f &nbsp;&nbsp;} &nbsp;&nbsp;1-\> { &nbsp;&nbsp;val f = fun Int.() :Boolean { return true} &nbsp;&nbsp;f &nbsp;&nbsp;} &nbsp;&nbsp;else -\> throw Exception("gah") } {code}

Is there no way to make it work like this :

{code}  
fun operation(int:Int) = when (int) {  
&nbsp;&nbsp;0-\> fun Int.() :Boolean { return true}  
&nbsp;&nbsp;1-\> fun Int.() :Boolean { return true}  
&nbsp;&nbsp;else -\> throw Exception(“gah”)  
}  
{code}

If I write that, I get all kinds of error&nbsp;&nbsp;like …you have to name function (name an anonymous function ? seriously ?), …  
I get that it’s related to extension functions expression/litteral but this feels really dirty and unkotlin 😕

---

<div class="post-metadata">

**Author:** ![abreslav](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/abreslav/32/8279_2.png) [@abreslav](https://discuss.kotlinlang.org/u/abreslav)\
**Post date:** [October 24, 2015, 9:23pm UTC](https://discuss.kotlinlang.org/t/function-expression-in-when/63/2 "2015-10-24T21:23:35Z")

</div>

Looks like a bug. Please report to the issue tracker
