{"id":36387122,"url":"https://github.com/piku235/jungi-common","last_synced_at":"2026-01-11T15:03:38.132Z","repository":{"id":44363951,"uuid":"391432287","full_name":"piku235/jungi-common","owner":"piku235","description":"A minimal library that defines primitive building blocks of PHP code.","archived":false,"fork":false,"pushed_at":"2025-11-30T11:52:45.000Z","size":88,"stargazers_count":28,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-12-02T16:58:27.811Z","etag":null,"topics":["equatable","php","result"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/piku235.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-07-31T18:15:51.000Z","updated_at":"2025-11-30T11:52:48.000Z","dependencies_parsed_at":"2025-09-28T16:00:43.980Z","dependency_job_id":null,"html_url":"https://github.com/piku235/jungi-common","commit_stats":null,"previous_names":["piku235/jungi-common"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/piku235/jungi-common","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piku235%2Fjungi-common","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piku235%2Fjungi-common/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piku235%2Fjungi-common/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piku235%2Fjungi-common/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/piku235","download_url":"https://codeload.github.com/piku235/jungi-common/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piku235%2Fjungi-common/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28309705,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T14:58:17.114Z","status":"ssl_error","status_checked_at":"2026-01-11T14:55:53.580Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["equatable","php","result"],"created_at":"2026-01-11T15:03:37.585Z","updated_at":"2026-01-11T15:03:38.127Z","avatar_url":"https://github.com/piku235.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🌱 jungi/common\n\n[![CI](https://github.com/jungi-php/common/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/jungi-php/common/actions/workflows/continuous-integration.yml)\n![PHP](https://img.shields.io/packagist/php-v/jungi/common)\n\nA minimal library that defines primitive building blocks of PHP code. It defines basic types and useful functions.\n\n**Primitive types:**\n\n* [`Equatable\u003cT\u003e`](https://piku235.gitbook.io/jungi-common/equatable)\n* [`Result\u003cT,E\u003e`](https://piku235.gitbook.io/jungi-common/result)\n\n## Installation\n\n```text\ncomposer require jungi/common\n```\n\n## Documentation\n\n[GitBook](https://piku235.gitbook.io/jungi-common)\n\n## Quick insight\n\n### Equatable\n\n```php\n/** @implements Equatable\u003cself\u003e */\nclass Phone implements Equatable\n{\n    public function __construct(private string $value) {}\n    \n    public function equals(self $other): bool\n    {\n        return $this-\u003evalue === $other-\u003evalue;\n    }\n}\n\nassert(true === (new Phone('(321) 456-1234'))-\u003eequals(new Phone('(321) 456-1234')));\nassert(false === (new Phone('(321) 456-1234'))-\u003eequals(new Phone('(454) 456-1234')));\n```\n\n### Result\n\n```php\nfinal class Student\n{\n    public function __construct(\n        public readonly StudentId $id,\n        private(set) bool $active,\n        private(set) string $name,\n    ) {}\n}\n\nenum ClassEnrollmentError: string {\n    case InactiveStudent = 'inactive_student';\n    case StudentAlreadyEnrolled = 'student_already_enrolled';\n    case NoSeatsAvailable = 'no_seats_available';\n}\n\nfinal class Class_\n{\n    public function __construct(\n        public readonly ClassId $id,\n        private(set) int $numberOfSeats,\n        /** @var StudentId[] */\n        private(set) array $students,\n    ) {}\n    \n    /** @return Result\u003cvoid, ClassEnrollmentError\u003e */\n    public function enroll(Student $student): Result\n    {\n        if (!$student-\u003eactive) {\n            return Result::error(ClassEnrollmentError::InactiveStudent);\n        }\n        if (in_iterable($student-\u003eid(), $this-\u003estudents)) {\n            return Result::error(ClassEnrollmentError::StudentAlreadyEnrolled);\n        }\n        if (count($this-\u003estudents) \u003e= $this-\u003enumberOfSeats) {\n            return Result::error(ClassEnrollmentError::NoSeatsAvailable);\n        }\n        \n        $this-\u003estudents[] = $student-\u003eid();\n        \n        return Result::ok();\n    }\n}\n\nclass ClassController\n{\n    // PUT /classes/{classId}/students/{studentId}\n    public function enrollToClass(string $classId, string $studentId)\n    {\n        // ... fetch the class and the student\n        $r = $class-\u003eenroll($student);\n        \n        if ($r-\u003eisOk()) {\n            return $this-\u003ecreated();\n        }\n        \n        return match ($r-\u003eerror) {\n            ClassEnrollmentError::StudentAlreadyEnrolled =\u003e $this-\u003enoContent(),\n            default =\u003e $this-\u003econflict($error),\n        };\n    }\n}\n```\n\n### Functions\n\n```php\nuse function Jungi\\Common\\equals;\nuse function Jungi\\Common\\in_iterable;\nuse function Jungi\\Common\\iterable_unique;\nuse function Jungi\\Common\\array_equals;\n\n/** @implements Equatable\u003cself\u003e */\nclass ContactInformation implements Equatable\n{\n    public function __construct(\n        private Phone $phone,\n        private ?Phone $mobile = null\n    ) {}\n\n    public function equals(self $other): bool\n    {\n        return $this-\u003ephone-\u003eequals($other-\u003ephone)\n            \u0026\u0026 equals($this-\u003emobile, $other-\u003emobile);\n    }\n}\n\n// equals()\n\n$a = new ContactInformation(new Phone('(321) 456-1234'), new Phone('(886) 456-6543'));\n$b = new ContactInformation(new Phone('(321) 456-1234'), new Phone('(886) 456-6543'));\nassert(true === equals($a, $b);\n\n$a = new ContactInformation(new Phone('(321) 456-1234'));\n$b = new ContactInformation(new Phone('(321) 456-1234'), new Phone('(886) 456-6543'));\nassert(false === equals($a, $b);\n\n// array_equals()\n\n$a = [new Phone('(321) 456-1234'), new Phone('(465) 799-4566')];\n$b = [new Phone('(321) 456-1234'), new Phone('(465) 799-4566')];\nassert(true === array_equals($a, $b));\n\n$a = [new Phone('(321) 456-1234'), new Phone('(465) 799-4566')];\n$b = [new Phone('(321) 456-1234')];\nassert(false === array_equals($a, $b));\n\n// in_iterable()\n\n$iterable = [new Phone('(656) 456-7765'), new Phone('(321) 456-1234')];\nassert(true === in_iterable(new Phone('(321) 456-1234'), $iterable));\nassert(false === in_iterable(new Phone('(232) 456-1234'), $iterable));\n\n// iterable_unique()\n\n$unique = iterable_unique([\n    new Phone('(321) 456-1234'),\n    new Phone('(465) 799-4566'),\n    new Phone('(321) 456-1234'),\n]);\n$expected = [\n    new Phone('(321) 456-1234'),\n    new Phone('(465) 799-4566'),\n];\nassert(true === array_equals($expected, $unique));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiku235%2Fjungi-common","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpiku235%2Fjungi-common","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiku235%2Fjungi-common/lists"}