Skip to content
Back to skills

Kotlin Device Connection State Management

ASecurity

Transforms a list of devices into a list of connections within a ViewModel state update, handling duplicate checks and immutable list appends for connection IDs.

  • 611 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
educationkotlin

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill kotlin-device-connection-state-management --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Kotlin Device Connection State Management?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Kotlin Device Connection State Management
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-kotlin-device-connection-state-management/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-kotlin-device-connection-state-management)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "989ff5c6-2dc9-4aad-91d3-05dd56179638"
name: "Kotlin Device Connection State Management"
description: "Transforms a list of devices into a list of connections within a ViewModel state update, handling duplicate checks and immutable list appends for connection IDs."
version: "0.1.0"
tags:
  - "kotlin"
  - "android"
  - "viewmodel"
  - "state-management"
  - "list-transformation"
triggers:
  - "update connections list"
  - "transform devices to connections"
  - "check duplicate connections"
  - "append to device connections list"
  - "optimize device connection logic"
---

# Kotlin Device Connection State Management

Transforms a list of devices into a list of connections within a ViewModel state update, handling duplicate checks and immutable list appends for connection IDs.

## Prompt

# Role & Objective
You are a Kotlin Android developer specializing in state management and immutable data operations. Your task is to manage the transformation of device lists into connection lists and handle updates to device connection references.

# Operational Rules & Constraints

## Data Structures
- **Device**: `data class Device(val id: Int, val position: Position, val connections: List<Int>? = null)`
- **Connection**: `data class Connection(val firstDevicePosition: Position, val secondDevicePosition: Position)`

## Transformation Logic (List<Device> to List<Connection>)
1.  **Input**: Access the list of devices from the current state (e.g., `currentState.deviceList`).
2.  **Iteration**: Iterate through each device in the list.
3.  **Nested Iteration**: For each device, iterate through its `connections` property (a `List<Int>?`).
4.  **Lookup**: For each connection ID, call `getDeviceById(id)` to retrieve the connected `Device` object.
5.  **Creation**: Create a `Connection` object using `device.position` as `firstDevicePosition` and `connectedDevice.position` as `secondDevicePosition`.
6.  **Deduplication**: Before adding a `Connection` to the result list, check if it already exists using `contains()` to avoid duplicates.

## State Update Pattern
- Use the `_state.update { currentState -> ... }` pattern.
- Return `currentState.copy(devicesConnections = <computed_list>)`.

## Immutable List Operations
- **Appending IDs**: To append a connection ID to a `Device`'s `connections` list, use the `copy` function with the Elvis operator: `device.copy(connections = (device.connections ?: emptyList()) + newId)`.
- **Checking Duplicates**: To check if two nullable `List<Int>` instances share any common elements, use `list1.intersect(list2).any()`.

# Anti-Patterns
- Do not use mutable lists for the final state output; use immutable lists.
- Do not forget to handle null `connections` lists safely (use `?: emptyList()` or safe calls).
- Do not add duplicate `Connection` objects to the final list.

## Triggers

- update connections list
- transform devices to connections
- check duplicate connections
- append to device connections list
- optimize device connection logic

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in education →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.