intuit / intuit/hooks

Functional Hook APIs

Open
#37 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Kotlin
Stars
42
Forks
6
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**

When tapping a hook that provides an abstract data type, we may _only_ care about a specific implementation. A simple early return allows us to "filter" out types we don't care about:

```kotlin
interface Super

class A : Super
class B : Super

val hook: SyncHook<(Super) -> Unit>
hook.tap(name) { super ->
if (super !is A) return@tap

// ...
}
```

**Describe the solution you'd like**

It'd be awesome to have functional methods for hooks, such that we can patternize filtering, data manipulation, etc.

```kotlin
hook.filterIsInstance().tap(name) { a ->
// ...
}
```

**Describe alternatives you've considered**

Tapping can effectively be thought of as collecting. Maybe it's worth adopting similar terminology? Probably not. Maybe a conversion layer to `Flow`s would solve better than trying to coerce hooks as a `Flow`-like data type.

**Additional context**

This is somewhat difficult to consider for the more complex hook types, since return value is more important. We'd want to ensure we have appropriate handling for each hook type, or not support certain hook types at all.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.