⚡ fonksiyon

option_var_mı

fonksiyon option_var_mı

Result and Option Module

Modern error handling without exceptions.

Hata yönetimi için Option ve Result tipleri.

Features / Özellikler

Option Type

Represents presence or absence of a value (like Rust's Option or Haskell's Maybe).

Bir değerin var olup olmadığını temsil eder (Rust'un Option veya Haskell'in Maybe tipi gibi).

  • Some(T) / Bazı(T): Value exists / Değer var
  • None / Hiç: No value / Değer yok

Result Type

Represents success or failure (like Rust's Result or Haskell's Either).

Başarı veya hata durumunu temsil eder (Rust'un Result veya Haskell'in Either tipi gibi).

  • Ok(T) / Tamam(T): Success with value / Başarılı sonuç
  • Err(E) / Hata(E): Error with error value / Hata mesajı

Example / Örnek

kullan result

// Option usage / Option kullanımı
değişken kullanıcı = bul_kullanıcı(id)
eşleşme kullanıcı yap
Bazı[u] => io.println("Kullanıcı: {u.ad}"),
Hiç => io.println("Kullanıcı bulunamadı")
son

// Result usage / Result kullanımı
değişken dosya = io.open("config.txt", "Read")?
eşleşme dosya yap
Tamam[f] => // process file / dosyayı işle,
Hata[e] => io.eprintln("Hata: {e}")
son

Philosophy / Felsefe

No exceptions! Errors are values. / Hariç durum yok! Hatalar değerdir.

  • Explicit error handling / Açık hata yönetimi
  • Compiler-enforced / Derleyici zorlar
  • Composable with ? operator / ? operatörü ile birleştirilebilir

📍 Kaynak Kodu

Satır 0