Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

feat: handle rune #814

Merged
merged 3 commits into from
Mar 28, 2023
Merged

feat: handle rune #814

merged 3 commits into from
Mar 28, 2023

Conversation

nythrox
Copy link
Contributor

@nythrox nythrox commented Mar 27, 2023

#790

Usage:

const value = Rune.constant(0 as number | string)

// match by class
value.handle(String, (num) => Number(num))
// match by predicate
value.handle((num): str is String => typeof num ==  "string", (num) => Number(num))
// match by value
value.handle("", () => undefined)

possible changes:

  • change name of RunMatch (RunHandle is already taken, maybe refactor)
  • handleError function

@nythrox
Copy link
Contributor Author

nythrox commented Mar 27, 2023

Some thoughts:

  • the alt parameter in handle() could receive T instead of ValueRune<T, never>. I think T is easier to use, but ValueRune encourages serializable code (should we treat this differently for lib devs x end users?)

  • a handleError would allow you to do the same thing, but on the U channel

  • having a Rune.error() would allow us to type errors (!) and easily handle/rehandle values. You could use this in chain, filter, etc. to change the channels of a value/error, handle/transform it, etc

rune/ValueRune.ts Outdated Show resolved Hide resolved
rune/ValueRune.ts Outdated Show resolved Hide resolved
rune/ValueRune.ts Outdated Show resolved Hide resolved
@nythrox nythrox added this pull request to the merge queue Mar 28, 2023
Merged via the queue into main with commit 149aa08 Mar 28, 2023
@nythrox nythrox deleted the feat/handle branch March 28, 2023 14:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants