No description
Find a file
2025-04-19 11:07:21 +05:30
src add: sugar for results 2025-04-19 11:06:32 +05:30
tests feat: initial commit 2025-04-17 12:21:45 +05:30
.gitignore feat: initial commit 2025-04-17 12:21:45 +05:30
README.md xxx: update README.md 2025-04-19 11:07:21 +05:30
shakar.nimble add: sugar for results 2025-04-19 11:06:32 +05:30

shakar

Shakar (/ˈʃək.kəɾ/) is a library that contains a bunch of syntactic sugar for the Nim programming language.
This package exists because a lot of these utilities apparently do not match Nim's safety guarantees (albeit it shouldn't really matter if you're paying attention). See this PR

Shakkar means "sugar" in Hindi. :^)

This library also aims to remove all the "sugar" files in all of the different Ferus projects and unify them under a single, easy-to-modify library.

basic usage

optional types

import std/options
import pkg/shakar

var nam = some("John")
assert *nam    ## `*` is used to check if the optional has a value

var age = none(uint8)
assert !age    ## `!` is used to check if the optional is empty

nam.applyThis:
  ## `applyThis` gives you a mutable `this` which is either
  ## the value of the optional if it has one, or the default
  ## value of that type (`default(T)`)
  this &= " Doe"

age.applyThis:
  assert this == 0 ## default initialized value since the optional is empty
  this = 28

## Store `nam` into the `name` value. This operator returns true if the optional wasn't empty.
if nam ?= name:
  echo "Name: " & name

if age ?= ayu:
  echo "Age: " & $ayu