stacks-network / stacks-network/stacks-core

Add function to discard error from `result` and return `optional`

Open
#7,152 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

clarity-new-builtin
Dominant language
Rust
Stars
3.1k
Forks
762
Avg merge
4d 6h
Merged PRs (30d)
76

Description

It would be nice to have the equivalent of Rust's Result::ok(), which discards the error from a Result and return an Option

Currently, to do this you would have to write:

(match (some-parsing-function bytes)
   ok (some ok)
   err none)

Consistent with the syntax I've proposed here for other type conversion functions, I propose adding to-optional to convert result types into optional types:

(to-optional (some-parsing-function bytes))

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the code that defines or exposes Clarity Result and Option conversions; the issue provides no file or test entry point. Compare the proposed to-optional behavior with the existing match example and the linked conversion syntax discussion. Done means a Result value can discard its error and return the corresponding Option value.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
blockchain
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.