(module main)

(import std.option (is_some_i32 is_none_i32 unwrap_or_i32 some_or_err_i32 some_i64 none_i64 unwrap_or_i64 some_or_err_i64 some_f64 none_f64 unwrap_or_f64 some_or_err_f64 some_bool none_bool unwrap_or_bool some_or_err_bool some_string none_string unwrap_or_string some_or_err_string))

(fn some_value ((value i32)) -> (option i32)
  (some i32 value))

(fn none_value () -> (option i32)
  (none i32))

(fn workspace_i32_bridge_ok () -> bool
  (if (match (some_or_err_i32 (some_value 42) 5)
    ((ok payload)
      (= payload 42))
    ((err code)
      false))
    (match (some_or_err_i32 (none_value) 5)
      ((ok payload)
        false)
      ((err code)
        (= code 5)))
    false))

(fn workspace_i64_bridge_ok () -> bool
  (if (= (+ (unwrap_or_i64 (some_i64 40i64) 0i64) (unwrap_or_i64 (none_i64) 2i64)) 42i64)
    (if (match (some_or_err_i64 (some_i64 42i64) 6)
      ((ok payload)
        (= payload 42i64))
      ((err code)
        false))
      (match (some_or_err_i64 (none_i64) 6)
        ((ok payload)
          false)
        ((err code)
          (= code 6)))
      false)
    false))

(fn workspace_f64_bridge_ok () -> bool
  (if (= (+ (unwrap_or_f64 (some_f64 40.0) 0.0) (unwrap_or_f64 (none_f64) 2.0)) 42.0)
    (if (match (some_or_err_f64 (some_f64 42.5) 7)
      ((ok payload)
        (= payload 42.5))
      ((err code)
        false))
      (match (some_or_err_f64 (none_f64) 7)
        ((ok payload)
          false)
        ((err code)
          (= code 7)))
      false)
    false))

(fn workspace_bool_bridge_ok () -> bool
  (if (unwrap_or_bool (some_bool true) false)
    (if (unwrap_or_bool (none_bool) true)
      (if (match (some_or_err_bool (some_bool true) 8)
        ((ok payload)
          payload)
        ((err code)
          false))
        (match (some_or_err_bool (none_bool) 8)
          ((ok payload)
            false)
          ((err code)
            (= code 8)))
        false)
      false)
    false))

(fn workspace_string_bridge_ok () -> bool
  (if (= (unwrap_or_string (some_string "slovo") "fallback") "slovo")
    (if (= (unwrap_or_string (none_string) "fallback") "fallback")
      (if (match (some_or_err_string (some_string "slovo") 9)
        ((ok payload)
          (= payload "slovo"))
        ((err code)
          false))
        (match (some_or_err_string (none_string) 9)
          ((ok payload)
            false)
          ((err code)
            (= code 9)))
        false)
      false)
    false))

(fn workspace_std_option_ok () -> bool
  (if (is_some_i32 (some_value 40))
    (if (is_none_i32 (none_value))
      (if (= (+ (unwrap_or_i32 (some_value 40) 0) (unwrap_or_i32 (none_value) 2)) 42)
        (if (workspace_i32_bridge_ok)
          (if (workspace_i64_bridge_ok)
            (if (workspace_f64_bridge_ok)
              (if (workspace_bool_bridge_ok)
                (workspace_string_bridge_ok)
                false)
              false)
            false)
          false)
        false)
      false)
    false))

(fn main () -> i32
  (if (workspace_std_option_ok)
    42
    1))

(test "workspace std option import"
  (workspace_std_option_ok))
