Promote Option to a compiler-built-in type
#1334
tranzystorekk
started this conversation in
Ideas & suggestions
Replies: 2 comments
-
|
Seconded! This would also unblock what I wanted to do for Only thing I’m not sure I agree on is the replacing usage of |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
A reference implementation I've been working on can be inspected in this branch: https://github.com/tranzystorek-io/gleam/tree/option-as-builtin |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This topic has not seen a good discussion so I've added it here.
Optionis considered a fundamental concept in functional-oriented languages, useful in expressing many fallible operations like obtaining elements from maps, representing results of iterator operations etc.Therefore it seems suitable that they be available in the Gleam prelude, i.e. as a core language type without the need to import them.
The proposal is as follows:
Optionusage/definitions wherever the type is used, similar toResultOptiondefinition fromgleam/optionOptiondefinitions/code to the js preludeResult(a, Nil)toOptionPros:
Optionis more expressive thanResult(a, Nil)in most situationsgleam/option, e.g. in stdlib itselfCons:
tryexpression support forResult, so some code would have to be rewritten withoption.to_result(Nil)Beta Was this translation helpful? Give feedback.
All reactions