> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Kotlin Not In

The `!in` operator is a negated membership operator used to evaluate whether a specific element is absent from a collection, range, or any object that defines a `contains` operator function. It serves as the syntactic inverse of the `in` operator.

At compile time, the Kotlin compiler desugars the `!in` expression into a negated method invocation of `contains()` on the right-hand operand.

```kotlin theme={"dark"}
val a = 5
val b = listOf(1, 2, 3)

// Syntactic expression
val isAbsent = a !in b

// Desugared JVM equivalent
val isAbsentDesugared = !b.contains(a)
```

## Operator Overloading

Because `!in` relies on the `contains` convention, it does not have its own dedicated operator function. To enable `!in` for a custom type, you must implement the `contains` function and mark it with the `operator` modifier. The function must accept the left-hand operand's type and return a `Boolean`.

```kotlin theme={"dark"}
class BoundingBox(val min: Int, val max: Int) {
    // Enables both 'in' and '!in'
    operator fun contains(point: Int): Boolean {
        return point in min..max
    }
}

val box = BoundingBox(0, 100)
val isOutside = 150 !in box // Evaluates to !box.contains(150)
```

## Type Resolution and Extension Functions

The right-hand operand is not strictly required to be a collection. The Kotlin compiler resolves the `contains` method either as a member function or as an extension function. For example, the standard library provides extension functions for `Iterable<T>`, `Array<T>`, and `CharSequence`, allowing `!in` to be evaluated against diverse data structures.

```kotlin theme={"dark"}
// Resolves to CharSequence.contains(Char)
val notAVowel = 'z' !in "aeiou" 

// Resolves to Iterable<T>.contains(T)
val element = 42
val objectList = listOf(1, 2, 3)
val notFound = element !in objectList 
```

## Syntax in Control Flow

Beyond standard boolean expressions, `!in` is a recognized branch condition within `when` expressions. In this context, the compiler implicitly applies the `!in` operator against the subject of the `when` block.

```kotlin theme={"dark"}
fun handleOutliers() { /* ... */ }
fun processStandard() { /* ... */ }

val subject = 150

when (subject) {
    !in 0..100 -> handleOutliers() // Desugars to: !(0..100).contains(subject)
    else -> processStandard()
}
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Kotlin Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
