1kinoti / stdx.nu Goto Github PK
View Code? Open in Web Editor NEWextensions for `nu std`
License: GNU General Public License v3.0
extensions for `nu std`
License: GNU General Public License v3.0
i've had a look at this package and it looks really cool, from a ton of aspects ๐ ๐
however, it's quite slow to parse ๐ค
i know it's the parser's fault but in an interactive use right now, it's not super nice...
in this context, i've written the super straightforward following modules ๐
Result
# nothing -> record<type: string, error: string>
export def Err [error: any] {{type: Err, error: $error}}
# nothing -> record<type: string, val: any>
export def Ok [val?: any] {{type: Ok, val: $val}}
export def unwrap-result [] {
let input = $in
match $input {
{type: Ok, val: $val} => $val,
{type: Err, error: $error} => {error make --unspanned {msg: $error}},
_ => {
error make --unspanned {
msg: $"Input of unwrap is not an Option: '($input)' of type ($input | describe)"
}
},
}
}
export def is-ok [] {
let input = $in
match $input {
{type: Ok, val: $_} => true,
{type: Err, error: $_} => false,
_ => {
error make --unspanned {
msg: $"Input of is-ok is not a Result: '($input)' of type ($input | describe)"
}
},
}
}
export def is-err [] {
let input = $in
match $input {
{type: Ok, val: $_} => false,
{type: Err, error: $_} => true,
_ => {
error make --unspanned {
msg: $"Input of is-err is not a Result: '($input)' of type ($input | describe)"
}
},
}
}
Option
# nothing -> record<type: string>
export def None [] {{type: None}}
# nothing -> record<type: string, val: any>
export def Some [val?: any] {{type: Some, val: $val}}
export def unwrap-option [] {
let input = $in
match $input {
{type: Some, val: $val} => $val,
{type: None} => {error make --unspanned {msg: "Unwrap on None variant of Option"}},
_ => {
error make --unspanned {
msg: $"Input of unwrap is not an Option: '($input)' of type ($input | describe)"
}
},
}
}
export def is-none [] {
let input = $in
match $input {
{type: Some} => false,
{type: None} => true,
_ => {
error make --unspanned {
msg: $"Input of is-none is not an Option: '($input)' of type ($input | describe)"
}
},
}
}
export def is-some [] {
let input = $in
match $input {
{type: Some} => true,
{type: None} => false,
_ => {
error make --unspanned {
msg: $"Input of is-none is not an Option: '($input)' of type ($input | describe)"
}
},
}
}
use std assert
use Option [None, Some, unwrap-option, is-none, is-some]
assert equal (None) (None)
assert not equal (None) (Some 123)
assert equal (Some 123) (Some 123)
assert (None | is-none)
assert not (None | is-some)
assert (Some 123 | is-some)
assert not (Some 123 | is-none)
assert equal (Some 123 | unwrap-option) 123
assert error {None | unwrap-option}
assert error {123 | is-some}
assert error {123 | is-none}
assert error {123 | unwrap-option}
use Result [Ok, Err, unwrap-result, is-err, is-ok]
assert equal (Err "my error") (Err "my error")
assert not equal (Err "my error") (Ok 123)
assert equal (Ok 123) (Ok 123)
assert (Err "my error" | is-err)
assert not (Err "my error" | is-ok)
assert (Ok 123 | is-ok)
assert not (Ok 123 | is-err)
assert equal (Ok 123 | unwrap-result) 123
assert error {Err "my error" | unwrap-result}
assert error {123 | is-ok}
assert error {123 | is-err}
assert error {123 | unwrap-result}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.