{"id":29416186,"url":"https://github.com/thedataflowclub/nullable","last_synced_at":"2025-07-11T19:01:59.941Z","repository":{"id":303100417,"uuid":"1014414330","full_name":"theDataFlowClub/nullable","owner":"theDataFlowClub","description":"A high-performance nullable type implementation for Nim","archived":false,"fork":false,"pushed_at":"2025-07-05T17:16:44.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-05T18:35:09.714Z","etag":null,"topics":["nim","null","null-safety","nullability","nullable","nullable-type","type-library","types"],"latest_commit_sha":null,"homepage":"","language":"Nim","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/theDataFlowClub.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-05T17:16:42.000Z","updated_at":"2025-07-05T17:32:23.000Z","dependencies_parsed_at":"2025-07-05T18:35:11.225Z","dependency_job_id":"d52af7b7-8775-48d4-a306-9b2ea82e1466","html_url":"https://github.com/theDataFlowClub/nullable","commit_stats":null,"previous_names":["thedataflowclub/nullable"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/theDataFlowClub/nullable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theDataFlowClub%2Fnullable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theDataFlowClub%2Fnullable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theDataFlowClub%2Fnullable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theDataFlowClub%2Fnullable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theDataFlowClub","download_url":"https://codeload.github.com/theDataFlowClub/nullable/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theDataFlowClub%2Fnullable/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264878580,"owners_count":23677450,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nim","null","null-safety","nullability","nullable","nullable-type","type-library","types"],"created_at":"2025-07-11T19:01:54.084Z","updated_at":"2025-07-11T19:01:59.861Z","avatar_url":"https://github.com/theDataFlowClub.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nullable for Nim\n\nA high-performance nullable type implementation for Nim, designed for explicit null handling without relying on `Option[T]` or reference types. Optimized for functional programming patterns with minimal runtime overhead.\n\n## Features\n\n- **Zero-cost abstractions**: Inlined operations with discriminated unions\n- **Functional programming**: Built-in `map`, `flatMap`, and `getOrElse` operations\n- **Type safety**: Compile-time null checking with runtime safety in debug mode\n- **Memory efficient**: Minimal footprint using tagged unions\n- **Comprehensive**: Works with primitives, objects, collections, and custom types\n- **Well-tested**: Extensive test suite covering edge cases and performance scenarios\n\n## Installation\n\nSimply copy `nullable.nim` to your project or add it to your Nim package.\n\n## Quick Start\n\n```nim\nimport nullable\n\n# Creating nullable values\nlet age = some(25)\nlet name = none[string]()\n\n# Checking for values\nif age.hasValue:\n  echo \"Age: \", age.value  # Age: 25\n\nif name.isNull:\n  echo \"Name not provided\"\n\n# Using defaults\nlet displayName = name.getOrElse(\"Anonymous\")\necho displayName  # Anonymous\n```\n\n## Functional Programming\n\n```nim\nimport nullable\n\nlet number = some(10)\n\n# Transform values\nlet doubled = number.map(proc(x: int): int = x * 2)\necho doubled  # Some(20)\n\n# Chain operations\nlet result = number\n  .map(proc(x: int): int = x * 3)\n  .map(proc(x: int): string = \"Result: \" \u0026 $x)\necho result  # Some(Result: 30)\n\n# Flat mapping\nlet validated = number.flatMap(proc(x: int): FastNullable[string] = \n  if x \u003e 0: some($x) else: none[string]())\necho validated  # Some(10)\n```\n\n## Working with Custom Types\n\n```nim\nimport nullable\n\ntype\n  Person = object\n    name: string\n    age: int\n\nlet person = some(Person(name: \"Alice\", age: 30))\nlet noPerson = none[Person]()\n\n# Type-safe access\nif person.hasValue:\n  echo person.value.name  # Alice\n\n# Functional operations\nlet personInfo = person.map(proc(p: Person): string = \n  p.name \u0026 \" is \" \u0026 $p.age \u0026 \" years old\")\necho personInfo  # Some(Alice is 30 years old)\n```\n\n## Type Aliases\n\nFor better readability, the module provides common type aliases:\n\n```nim\nimport nullable\n\nlet count: FastNullableInt = createFastNullableInt(42)\nlet message: FastNullableString = createFastNullableString(\"Hello\")\nlet flag: FastNullableBool = some(true)\n\n# Access with convenience functions\nif count.hasValue:\n  echo getFastIntValue(count)  # 42\n```\n\n## API Reference\n\n### Core Types\n\n- `FastNullable[T]` - Generic nullable type\n- `FastNullableInt`, `FastNullableString`, `FastNullableFloat`, `FastNullableBool` - Common type aliases\n\n### Constructors\n\n- `some[T](value: T)` - Create a nullable with a value\n- `none[T]()` - Create an empty nullable\n\n### Checking Values\n\n- `hasValue(): bool` - Returns true if contains a value\n- `isNull(): bool` - Returns true if empty\n- `value(): T` - Gets the value (unsafe - check hasValue first)\n\n### Functional Operations\n\n- `map[U](f: T -\u003e U): FastNullable[U]` - Transform the value if present\n- `flatMap[U](f: T -\u003e FastNullable[U]): FastNullable[U]` - Transform and flatten\n- `getOrElse(default: T): T` - Get value or return default\n\n### Utility\n\n- `$nullable` - String representation (`Some(value)` or `None`)\n- `==` - Equality comparison\n\n## Performance\n\nNullable is designed for performance:\n\n- Uses discriminated unions for minimal memory overhead\n- All operations are inlined for zero-cost abstractions\n- No heap allocations for the nullable wrapper itself\n- Efficient branching with simple boolean checks\n\n```bash\n\n=== Benchmark - FastNullable vs Option vs ref/nil ===\nFastNullable: 0.0832 seg. Resultado: 249999500000\nOption: 0.0596 seg. Resultado: 249999500000\nref/nil: 0.1063 seg. Resultado: 249999500000\n\n```\n\n## Testing\n\nRun the comprehensive test suite:\n\n```bash\nnim c -r nullable_unittest.nim\n```\n\nThe test suite includes:\n\n- Basic functionality tests\n- Edge case handling\n- Complex type operations\n- Functional programming patterns\n- Performance verification\n- Error handling in debug mode\n\n## Why FastNullable?\n\nWhile Nim's `Option[T]` is excellent for many use cases, FastNullable offers:\n\n- **Explicit null semantics** without reference types\n- **Extended functional API** with `flatMap` and chaining\n- **Performance optimization** for critical paths\n- **Custom domain modeling** with type aliases\n- **Clear intent** for nullable vs optional semantics\n\n## Contributing\n\nContributions are welcome! Please ensure:\n\n- All tests pass\n- New features include corresponding tests\n- Code follows the existing style\n- Performance implications are considered\n\n## License\n\nMIT License - see LICENSE file for details.\n\n## Credits\n\nDeveloped by David Ochoa with assistance from AI tools during development and optimization.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthedataflowclub%2Fnullable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthedataflowclub%2Fnullable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthedataflowclub%2Fnullable/lists"}