Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let's talk on 25/Aug 16 UTC! #28

Open
arthurfiorette opened this issue Aug 21, 2024 · 5 comments
Open

Let's talk on 25/Aug 16 UTC! #28

arthurfiorette opened this issue Aug 21, 2024 · 5 comments
Assignees

Comments

@arthurfiorette
Copy link
Owner

This proposal has garnered significant attention from the community, sparking some exciting new ideas and raising important questions. To continue this momentum, I’m organizing a small Discord call where everyone can share their thoughts and help us make decisions together.

The meeting will be in English. Don’t worry if your English isn't perfect—mine isn’t either! Everyone is welcome to join the conversation.

25 August 2024
16:00 UTC
English
on Discord

Discord:
https://discord.gg/YGEEgVeY?event=1275801482427367465

Google calendar:
https://calendar.google.com/calendar/u/0/r/eventedit?dates=20240825T130000/20240825T130000&details=https://discord.com/invite/YGEEgVeY?event%3D1275801482427367465%0A%0Ahttps://github.com/arthurfiorette/proposal-safe-assignment-operator&location=Discord:+servidor+Kita,+meetings&text=Let%27s+talk+about+the+safe+assignment+operator

@arthurfiorette arthurfiorette self-assigned this Aug 21, 2024
@arthurfiorette arthurfiorette pinned this issue Aug 21, 2024
@ipenywis
Copy link

I recently made a video about it, and as far as I can tell, people love the new operator and handle errors as values instead of using try/catch.
Will share this in the comments: https://www.youtube.com/watch?v=eh5RYeprXDY

@arthurfiorette
Copy link
Owner Author

I saw your video @ipenywis!! it was awesome! Keep up the good work.

I wasn't expecting to gain so much attention by creating this proposal. Now I have to handle it :)

@ipenywis
Copy link

Ty @arthurfiorette and great work!
I'd be happy to help if this proposal moves forward and requires more hands on deck 🫡

@Ethergeist
Copy link

Ethergeist commented Aug 25, 2024

So I've seen a couple of articles and the aforementioned video on this, however I think this isn't a really necessary feature. One can trivially implement it in JS in multiple ways. (The one below only requires 27 lines of JS):

class Result {
  static ERR = 0;
  static OK = 1;
  type;
  data;
  constructor(data, type = Result.ERR) {
    this.data = data;
    this.type = type === Result.OK ? Result.OK : Result.ERR;
  }
  get error() {
    return this.type === Result.ERR ? this.data : undefined;
  }
  get result() {
    return this.type === Result.OK ? this.data : undefined;
  }
}

function Optional(fn) {
  return async function(...args) {
    try {
      const data = await fn.apply(fn, args);
      return new Result(data, Result.OK);
    } catch(error) {
      return new Result(error, Result.ERR)
    }
  }
}


function testOk(str) {
  return 'Everything is OK' + str;
}

function testErr(str) {
  throw Error('Error yeet!' + str)
}

const optionalOk = Optional(testOk);
const optionalErr = Optional(testErr);

const { result, error } = await optionalOk('Test1');
const { result: result2, error: error2 } = await optionalErr('Test1');

const okResult = await optionalOk('Test2');
const errResult = await optionalErr('Test2');

switch(okResult.type) {
  case Result.OK:
    console.log('Success', okResult.data);
    break;
  case Result.ERR:
  default:
    console.error('Failure', okResult.data);
}

switch(errResult.type) {
  case Result.OK:
    console.log('Success', okResult.data);
    break;
  case Result.ERR:
  default:
    console.error('Failure', okResult.data);
}

@arthurfiorette
Copy link
Owner Author

arthurfiorette commented Aug 27, 2024

Ok, based on the discussion that I had some hours after the scheduled time (almost no one showed up in time 😭). I'll be opening a new branch to rewrite this proposal following the most loved ideas proposed in issues here.

Probably will start doing that on 1 sep 2024.

Thanks for the help of everyone.

@arthurfiorette arthurfiorette unpinned this issue Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants