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
-
This topic has not seen a good discussion so I've added it here.
Option
is 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:
Option
usage/definitions wherever the type is used, similar toResult
Option
definition fromgleam/option
Option
definitions/code to the js preludeResult(a, Nil)
toOption
Pros:
Option
is more expressive thanResult(a, Nil)
in most situationsgleam/option
, e.g. in stdlib itselfCons:
try
expression support forResult
, so some code would have to be rewritten withoption.to_result(Nil)
Beta Was this translation helpful? Give feedback.
All reactions