# Shouldn't this work?

**URL:** https://discuss.kotlinlang.org/t/shouldnt-this-work/5259
**Category:** Language Design
**Created:** [November 4, 2017, 12:06am UTC](https://discuss.kotlinlang.org/t/shouldnt-this-work/5259 "2017-11-04T00:06:37Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![lonpalmer](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@lonpalmer](https://discuss.kotlinlang.org/u/lonpalmer)
#### Post date: [November 4, 2017, 12:06am UTC](https://discuss.kotlinlang.org/t/shouldnt-this-work/5259/1 "2017-11-04T00:06:37Z")

</div>

Two functions in a junit test:

`
assertEquals(unit1.isAlarm(), unit2.isAalrm())
`

Both functions return a Boolean.

I had to do this instead:  
`
val one = unit1.isAlarm()
val two = unit2.isAlarm()
assertEquals(one, two)
`

---

<div class="post-metadata">

### Author: ![ilya.gorbunov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ilya.gorbunov/32/1645_2.png) [@ilya.gorbunov](https://discuss.kotlinlang.org/u/ilya.gorbunov)
#### Post date: [November 4, 2017, 2:39am UTC](https://discuss.kotlinlang.org/t/shouldnt-this-work/5259/2 "2017-11-04T02:39:54Z")

</div>

Yes, the first one should work. Doesn’t it work for you?

---

<div class="post-metadata">

### Author: ![ilogico](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ilogico/32/3725_2.png) [@ilogico](https://discuss.kotlinlang.org/u/ilogico)
#### Post date: [November 4, 2017, 3:02pm UTC](https://discuss.kotlinlang.org/t/shouldnt-this-work/5259/3 "2017-11-04T15:02:06Z")

</div>

It should work without the typo.

---

<div class="post-metadata">

### Author: ![lonpalmer](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@lonpalmer](https://discuss.kotlinlang.org/u/lonpalmer)
#### Post date: [November 6, 2017, 2:56pm UTC](https://discuss.kotlinlang.org/t/shouldnt-this-work/5259/4 "2017-11-06T14:56:10Z")

</div>

OK I wrote that post in haste over the weekend. Here is the code. Actually I was compairing the isAlarm() result from one nullable type and one not nullable type. I’m confused because they both produce Boolean values (not nullable Booleans) so why isn’t the result of isAlarm() being evaluated? Or is it and I’m missing something?

```auto
data class Alarm(val date : Long, val type : Int);

class Unit
{
    val alarmList = mutableListOf<Alarm>();

    fun isAlarm() = {alarmList.size > 0}
}

```

Here’s the unit test:

```auto
import org.junit.Test

import org.junit.Assert.*
import org.junit.Before

class UnitTest
{
    var one : Unit? = null;

    @Before
    fun setupOne()
    {
        one = Unit();
    }

    @Test
    fun getAlarmList()
    {
    }

    @Test
    fun isAlarm()
    {
        val two = Unit();
        assertEquals(one?.isAlarm(), two.isAlarm())
    }

```

What am I missing?

---

<div class="post-metadata">

### Author: ![mslenc](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/mslenc/32/3861_2.png) [@mslenc](https://discuss.kotlinlang.org/u/mslenc)
#### Post date: [November 6, 2017, 3:31pm UTC](https://discuss.kotlinlang.org/t/shouldnt-this-work/5259/5 "2017-11-06T15:31:17Z")

</div>

isAlarm as written doesn’t return a boolean, it returns a function (of type `() -> Boolean`), because you wrapped it in `{}`

try with this:

```auto
fun isAlarm() = alarmList.isNotEmpty()

```

---

<div class="post-metadata">

### Author: ![lonpalmer](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@lonpalmer](https://discuss.kotlinlang.org/u/lonpalmer)
#### Post date: [November 6, 2017, 3:32pm UTC](https://discuss.kotlinlang.org/t/shouldnt-this-work/5259/6 "2017-11-06T15:32:59Z")

</div>

Thank you! I keep getting tripped up by that in Kotlin.

---

<div class="post-metadata">

### Author: ![pdvrieze](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/pdvrieze/32/1882_2.png) [@pdvrieze](https://discuss.kotlinlang.org/u/pdvrieze)
#### Post date: [November 7, 2017, 9:53am UTC](https://discuss.kotlinlang.org/t/shouldnt-this-work/5259/7 "2017-11-07T09:53:38Z")

</div>

There is a feature in the editor that will get intellij/android studio to display the actual return type used for the function even if you don’t write it (unless obvious). That feature may help you.
