Skip to content

Jedsek/geny

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

geny

(WIP.) ( The document is coming soon, sorry, I'm so busy :) )

Package Version Hex Docs

Inspired by rust's anyhow

gleam add geny
import geny.{type GResult}
import geny.ext.ensure

pub fn user_allowed(user_id: Int) -> GResult(String, String) {
  use <- ensure(must: user_id == 0, error: "Only user 0 is allowed")
  // ...
  // ...
  // ...
  Ok("Good")
}

user_allowed(0) |> should.be_ok
user_allowed(1) |> should.be_error
user_allowed(2) |> should.be_error

You could add context for GResult and print them:

import geny.{type GResult}
import geny/ext.{context, from, to_string}
import gleam/io

let result = Error("This is a error") |> from  //  <-- This convert/wrap normal `Result` into `GResult`  
let result = result 
  |> context("The context A") 
  |> context("The context B")
  |> context("The context C")

case result {
  Ok(_) -> io.println("Good ok!")
  Error(geny) -> io.println(geny |> to_string)
}

The output is:

error: This is a error

caused by:
  0: The context A
  1: The context B
  2: The context C

Further documentation can be found at https://hexdocs.pm/geny.

Development

gleam run   # Run the project
gleam test  # Run the tests
gleam shell # Run an Erlang shell

Releases

No releases published

Packages

No packages published

Languages