Skip to content

Instantly share code, notes, and snippets.

@Sceat
Last active September 1, 2021 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sceat/2532127db036dc2a1c5e8d8ac582ec18 to your computer and use it in GitHub Desktop.
Save Sceat/2532127db036dc2a1c5e8d8ac582ec18 to your computer and use it in GitHub Desktop.
Contain side-effects by boxing your IO calls or whatever you want
export const success = x => ({ success: x })
export const failure = x => ({ failure: x })
export default {
success,
failure,
}
{
"name": "result",
"version": "0.1.0",
"type": "module",
"main": "_result.js"
}
@Sceat
Copy link
Author

Sceat commented Sep 1, 2021

Result

Contain side-effects in your code by boxing your IO calls or whatever you want

📦 Install

npm i gist:2532127db036dc2a1c5e8d8ac582ec18

Usage

import Result from 'result'

async function purify() {
  try {
    return Result.success('buscu grupo para rn')
  } catch {
    return Result.failure({ oh: 'no :(' })
  }
}

const { success, failure } = await purify()

if (success) 
	console.log(success)
else 
	console.dir(failure)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment