{"id":13577444,"url":"https://github.com/kowainik/slist","last_synced_at":"2025-07-26T22:16:03.400Z","repository":{"id":53716506,"uuid":"177396550","full_name":"kowainik/slist","owner":"kowainik","description":"♾️ Sized list","archived":false,"fork":false,"pushed_at":"2024-05-11T16:22:50.000Z","size":81,"stargazers_count":46,"open_issues_count":8,"forks_count":6,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-07-02T21:33:02.806Z","etag":null,"topics":["data-structure","hacktoberfest","haskell","list","sized"],"latest_commit_sha":null,"homepage":"https://kowainik.github.io/projects/slist","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kowainik.png","metadata":{"funding":{"ko_fi":"kowainik","github":["vrom911"]},"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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-24T09:52:29.000Z","updated_at":"2024-05-11T16:22:53.000Z","dependencies_parsed_at":"2024-10-30T11:04:20.398Z","dependency_job_id":"c9a36bfd-4cb1-4846-b05a-5279f6f1d8b3","html_url":"https://github.com/kowainik/slist","commit_stats":{"total_commits":42,"total_committers":4,"mean_commits":10.5,"dds":0.09523809523809523,"last_synced_commit":"09e7c4279f954db18e27a60aa8569dc3458b24ad"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/kowainik/slist","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kowainik%2Fslist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kowainik%2Fslist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kowainik%2Fslist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kowainik%2Fslist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kowainik","download_url":"https://codeload.github.com/kowainik/slist/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kowainik%2Fslist/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265524896,"owners_count":23782056,"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":["data-structure","hacktoberfest","haskell","list","sized"],"created_at":"2024-08-01T15:01:21.534Z","updated_at":"2025-07-26T22:16:03.364Z","avatar_url":"https://github.com/kowainik.png","language":"Haskell","readme":"# slist\n\n[![GitHub CI](https://github.com/kowainik/slist/workflows/CI/badge.svg)](https://github.com/kowainik/slist/actions)\n[![Hackage](https://img.shields.io/hackage/v/slist.svg?logo=haskell)](https://hackage.haskell.org/package/slist)\n[![MPL-2.0 license](https://img.shields.io/badge/license-MPL--2.0-blue.svg)](LICENSE)\n\n\u003e ⚠️ Caution: this is a very opinionated library. There is no intention to replace the standard list data type.\n\u003e We are aware of every design decision we made for this package, and we are taking responsibility for that design.\n\u003e If you find it inappropriate, please, consider to use another library instead, that would fulfil your requirements.\n\nThis package introduces sized list data type — `Slist`. The data type\nhas the following shape:\n\n```haskell\ndata Slist a = Slist\n    { sList :: [a]\n    , sSize :: Size\n    }\n```\n\nAs you can see that along with the familiar list, it contains `Size` field that\nrepresents the size of the structure. Slists can be finite or infinite, and this\nis expressed with `Size`.\n\n```haskell\ndata Size\n    = Size Int\n    | Infinity\n```\n\n\u003e ⚠️ Caution: `Int` is used for the size by design. We had to make some trade-offs\n\u003e to provide the better (as we think) interface for users. For more details on the\n\u003e choice, see the Haddock documentation for the `Size` data type.\n\nThis representation of the list gives some additional advantages. Getting the\nlength of the list is the \"free\" operation (runs in `O(1)`). This property\nhelps to improve the performance for a bunch of functions like `take`, `drop`,\n`at`, etc. But also it doesn't actually add any overhead on the existing\nfunctions.\n\nAlso, this allows to write a number of safe functions like `safeReverse`,\n`safeHead`, `safeLast`, `safeIsSuffixOf`, etc.\n\n## Comparison\n\nCheck out the comparison table between lists and slists performance.\n\n| Function          | list (finite)                     | list (infinite)             | Slist (finite)                         | Slist (infinite) |\n|-------------------|-----------------------------------|-----------------------------|----------------------------------------|------------------|\n| `length`          | `O(n)`                            | \u003c_hangs_\u003e                   | `O(1)`                                 | `O(1)`           |\n| `safeLast`        | `O(n)`                            | \u003c_hangs_\u003e                   | `O(n)`                                 | `O(1)`           |\n| `init`            | `O(n)`                            | \u003c_works infinitely_\u003e        | `O(n)`                                 | `O(1)`           |\n| `take`            | `O(min i n)`                      | `O(i)`                      | `0 \u003c i \u003c n`: `O(i)`; otherwise: `O(1)` | `O(i)`           |\n| `at`              | `O(min i n)` (run-time exception) | `O(i)` (run-time exception) | `0 \u003c i \u003c n`: `O(i)`; otherwise: `O(1)` | `O(i)`           |\n| `safeStripPrefix` | `O(m)`                            | `O(m)` (can hang)           | `O(m)`                                 | `O(m)`           |\n\n## Potential usage cases\n\n* When you ask the size of the list too frequently.\n* When you need to convert to data structures that require to know the list\n  size in advance for allocating an array of the elements.\n  _Example:_ [Vector data structure](https://hackage.haskell.org/package/vector).\n* When you need to serialise lists.\n* When you need to control the behaviour depending on the finiteness of the list.\n* When you need a more efficient or safe implementation of some functions.\n","funding_links":["https://ko-fi.com/kowainik","https://github.com/sponsors/vrom911"],"categories":["Haskell"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkowainik%2Fslist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkowainik%2Fslist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkowainik%2Fslist/lists"}