{"id":25979268,"url":"https://github.com/bjorg/simple","last_synced_at":"2025-07-05T13:33:54.547Z","repository":{"id":17459071,"uuid":"20233057","full_name":"bjorg/Simple","owner":"bjorg","description":"A Haskell library to simplify common functionality that recovering imperative programmers might be missing.","archived":false,"fork":false,"pushed_at":"2014-07-03T06:33:35.000Z","size":252,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-24T07:09:23.777Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bjorg.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}},"created_at":"2014-05-27T19:43:08.000Z","updated_at":"2014-07-22T21:20:02.000Z","dependencies_parsed_at":"2022-09-23T19:30:51.378Z","dependency_job_id":null,"html_url":"https://github.com/bjorg/Simple","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjorg%2FSimple","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjorg%2FSimple/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjorg%2FSimple/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjorg%2FSimple/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bjorg","download_url":"https://codeload.github.com/bjorg/Simple/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241978507,"owners_count":20051990,"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":[],"created_at":"2025-03-05T06:29:11.799Z","updated_at":"2025-03-05T06:29:12.430Z","avatar_url":"https://github.com/bjorg.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"Simple\n======\n\nA Haskell package to simplify common functionality that recovering imperative programmers might be missing.\n\n# Installing\n\nThe package definition has not yet been submitted to enable a simple `cabal` installation. Luckily, doing it using `git` is not that much harder:\n```\ngit clone https://github.com/bjorg/Simple.git\ncabal install Simple\n```\n\n# Module: Simple.Maybe\n\n### (??) :: Maybe a -\u003e a -\u003e a\nCheck if a Maybe value has an actual value or not. If it does, return the actual value, otherwise return the second argument as default value.\n\n```haskell\nghci \u003e (Just 1) ?? 2\n1\nghci \u003e Nothing ?? 2\n2\n```\n\n# Module: Simple.Text\n\nCollection of functions to operate on `Text` values. `Simple.Text` is built on `Data.Text` and fully compatible with it. It exposes most of the functions with new, more expressive names. In addition, it also provides new convenience functions for case-insensitive operations. Function names are explicit enough to avoid the module needing to be included in a qualified manner. Aside from making the entire module available at once, it also promotes better code readability.\n\nMake sure to use the `OverloadedStrings` extension to avoid explicit `toText` calls for string literals. The samples in this document assume the extension is enabled.\n\nTo get started using `ghci`, enter the following:\n```\n~\u003e ghci -XOverloadedStrings\nghci \u003e :m + Simple.Text\n```\n\nDifferent from traditional Haskell functions, the primary argument is the `Text` value to be operated on. For instance:\n```haskell\nghci \u003e \"hello world\" `startsWithText` \"hello\"\nTrue\n```\n\n## Conversions\n\n`Simple.Text` introduces the `ToText` type class, which is used for all conversions to `Text` values. Using a type class makes it easy to introduce additional conversions from other types without introducing hard to remember names.\n\nThe `ToText` type class is defined as follows:\n```haskell\nclass ToText a where\n    toText :: a -\u003e Text\n```\n\n### toText :: Char -\u003e Text\nConvert a character to a `Text` value.\n\n```haskell\nghci \u003e toText '!'\n\"!\"\n```\n### toText :: String -\u003e Text\nConvert a string value to a `Text` value.\n\n```haskell\nghci \u003e toText \"hi!\"\n\"hi!\"\n```\n## Basic interface\n\n### appendChar :: Text -\u003e Char -\u003e Text\nAppend a character to a `Text` value.\n\n```haskell\nghci \u003e \"hi\" `appendChar` '!'\n\"hi!\"\n```\n\n### appendText :: Text -\u003e Text -\u003e Text\nAppend the second `Text` value to the first.\n\n```haskell\nghci \u003e \"hello\" `appendText` \" world!\"\n\"hello world!\"\n```\n\n### lengthText :: Text -\u003e Int\nGet the length of a `Text` value.\n\n```haskell\nghci \u003e lengthText \"hi\"\n2\n```\n\n### prependChar :: Text -\u003e Char -\u003e Text\nAppend a character to the beginning of a `Text` value.\n\n```haskell\nghci \u003e \"i!\" prependChar 'h'\n\"hi!\"\n```\n\n### prependText :: Text -\u003e Text -\u003e Text\nAppend the second `Text` value to the beginning of the first value.\n\n```haskell\nghci \u003e \"world!\" `prependText` \"hello \"\n\"hello world!\"\n```\n\n### showText :: Show a =\u003e a -\u003e Text\nRender value as `Text` value.\n\n```haskell\nghci \u003e show 123\n\"123\"\n```\n\n### (...) :: Text -\u003e Text -\u003e Text\nAppend the second `Text` value to the first. This operator is shorthand for `appendText`.\n\n```haskell\nghci \u003e \"hello\" ... \" world!\"\n\"hello world!\"\n```\n\n## Transformations\n\n### joinText :: Text -\u003e [Text] -\u003e Text\nJoin all `Text` values into a single `Text` value using the first argument as separator between them.\n\n```haskell\nghci \u003e joinText \" \" [\"hello\",\"world\"]\n\"hello world\"\n```\n\n### removeChar :: Text -\u003e Char -\u003e Text\nRemove all occurrences of a `Char` value from the `Text` value.\n\n```haskell\nghci \u003e \"hello world\" `removeChar` 'l'\n\"heo word\"\n```\n\n### removeText :: Text -\u003e Text -\u003e Text\nRemove all occurrences of the second `Text` value from the first one.\n\n```haskell\nghci \u003e \"hello world\" `removeText` \"ll\"\n\"heo world\"\n```\n\n### replaceText :: Text -\u003e (Text, Text) -\u003e Text\nReplace all occurrences of a `Text` value with another. The first argument is the `Text` value in which to perform the substitutions. The second argument is a tuple with the `Text` value to search for and its replacement.\n\n```haskell\nghci \u003e \"hi!\" `replaceText` (\"hi\", \"bye\")\n\"bye!\"\n```\n\n### splitText :: Text -\u003e Text -\u003e [Text]\nSplit a `Text` value on each occurrence of the second argument.\n\n```haskell\nghci \u003e \"hello world\" `splitText` \" \"\n[\"hello\", \"world\"]\n```\n\n### subText :: Text -\u003e (Int, Maybe Int) -\u003e Text\nExtract a `Text` value from another one. The second argument is a tuple with the offset and optional length. A negative offset indicates that the extraction should begin from the end of the `Text` value. If the length value is omitted, all remaining characters are extracted.\n\n```haskell\nghci \u003e \"hello world\" `subText` (2, Just 2)\n\"ll\"\nghci \u003e subText \"hello world\" (0, Just 100)\n\"hello world\"\nghci \u003e subText \"hello world\" (100, Just 0)\n\"\"\nghci \u003e \"hello world\" `subText` (6, Nothing)\n\"world\"\nghci \u003e \"hello world\" `subText` (-5, Just 2)\n\"wo\"\nghci \u003e \"hello world\" `subText` (-5, Nothing)\n\"world\"\n```\n\n### toLowerText :: Text -\u003e Text\nConvert a `Text` value to its lowercase equivalent. Note this conversion is not locale specific.\n\n```haskell\nghci \u003e toLowerText \"Hi!\"\n\"hi!\"\n```\n\n### toUpperText :: Text -\u003e Text\nConvert a `Text` value to its uppercase equivalent. Note this conversion is not locale specific.\n\n```haskell\nghci \u003e toUpperText \"hi!\"\n\"HI!\"\n```\n\n### trimText :: Text -\u003e Text\nRemove whitespace from the beginning and end of the `Text` value.\n\n```haskell\nghci \u003e trimText \"  hi!  \"\n\"hi!\"\n```\n\n### trimEndText :: Text -\u003e Text\nRemove whitespace only from the end of the `Text` value.\n\n```haskell\nghci \u003e trimEndText \"  hi!  \"\n\"  hi!\"\n```\n\n### trimStartText :: Text -\u003e Text\nRemove whitespace only from the beginning of the `Text` value.\n\n```haskell\nghci \u003e trimStartText \"  hi!  \"\n\"hi!  \"\n```\n\n## Comparisons\n\n### compareText :: Text -\u003e Text -\u003e Ordering\nCompare two `Text` values.\n\n```haskell\nghci \u003e \"hi\" `compareText` \"bye\"\nGT\n```\n\n### compareIgnoreCaseText :: Text -\u003e Text -\u003e Ordering\nCompare two `Text` values in case-insensitive manner.\n\n```haskell\nghci \u003e \"hi\" `compareIgnoreCaseText` \"Hi\"\nEQ\n```\n\n### containsText :: Text -\u003e Text -\u003e Bool\nCheck if the second `Text` value is contained in the first `Text` value.\n\n```haskell\nghci \u003e \"hello world\" `containsText` \"hello\"\nTrue\n```\n### containsIgnoreCaseText :: Text -\u003e Text -\u003e Bool\nCheck if the second `Text` value is contained in the first `Text` value in a case-insentitive manner.\n\n```haskell\nghci \u003e \"hello world\" `containsText` \"WORLD\"\nTrue\n```\n\n### equalsText :: Text -\u003e Text -\u003e Bool\nCompare if two `Text` values are identical.\n\n```haskell\nghci \u003e \"hi\" `equalsText` \"hi\"\nTrue\n```\n\n### equalsIgnoreCaseText :: Text -\u003e Text -\u003e Bool\nCompare if two `Text` values are identical in a case-insensitive manner.\n\n```haskell\nghci \u003e \"hi\" `equalsText` \"HI\"\nTrue\n```\n\n### isEmptyOrWhitespaceText :: Text -\u003e Bool\nCheck if the `Text` value corresponds to the empty `Text` value after trimming all whitespace from it.\n\n```haskell\nghci \u003e isEmptyOrWhitespaceText \"\"\nTrue\nghci \u003e isEmptyOrWhitespaceText \" \"\nTrue\nghci \u003e isEmptyOrWhitespaceText \"hi\"\nFalse\n```\n\n### isEmptyText :: Text -\u003e Bool\nCheck if the `Text` value corresponds to the empty `Text` value.\n\n```haskell\nghci \u003e isEmptyText \"\"\nTrue\nghci \u003e isEmptyText \"hi\"\nFalse\n```\n\n### isNotEmptyOrWhitespaceText :: Text -\u003e Bool\nCheck if the `Text` value is not the empty `Text` value after trimming all whitespace from it.\n\n```haskell\nghci \u003e isNotEmptyOrWhitespaceText \"\"\nFalse\nghci \u003e isNotEmptyOrWhitespaceText \" \"\nFalse\nghci \u003e isNotEmptyOrWhitespaceText \"hi\"\nTrue\n```\n\n### isNotEmptyText :: Text -\u003e Bool\nCheck if the `Text` value is not to the empty `Text` value.\n\n```haskell\nghci \u003e isNotEmptyText \"\"\nFalse\nghci \u003e isNotEmptyText \"hi\"\nTrue\n```\n\n### startsWithText :: Text -\u003e Text -\u003e Bool\nCheck if the first `Text` value starts with the second one.\n\n```haskell\nghci \u003e \"hello world\" `startsWithText` \"hello\"\nTrue\n```\n\n### startsWithIgnoreCaseText :: Text -\u003e Text -\u003e Bool\nCheck if the first `Text` value starts with the second one in case-insensitive manner.\n\n```haskell\nghci \u003e \"hello world\" `startsWithText` \"HeLlO\"\nTrue\n```\n\n### endsWithText :: Text -\u003e Text -\u003e Bool\nCheck if the first `Text` value ends with the second one.\n\n```haskell\nghci \u003e \"hello world\" `endsWithText` \"world\"\nTrue\n```\n\n### endsWithIgnoreCaseText :: Text -\u003e Text -\u003e Bool\nCheck if the first `Text` value ends with the second one in a case-insensitive manner.\n\n```haskell\nghci \u003e \"hello world\" `endsWithText` \"WoRlD\"\nTrue\n```\n\n```haskell\nghci \u003e sortIgnoreCaseText [\"hi\",\"bye\",\"World\",\"Hello\"]\n[\"bye\",\"Hello\",\"hi\",\"World\"]\n```\n\n## Searching\n\n### indexOfAnyChar :: Text -\u003e [Char] -\u003e Maybe Int\nFind the first occurrence of any of the `Char` values in the `Text` value.\n\n```haskell\nghci \u003e \"hello world\" `indexOfAnyChar` ['E', 'o']\nJust 4\n```\n\n### indexOfAnyIgnoreCaseChar :: Text -\u003e [Char] -\u003e Maybe Int\nFind the first occurrence of any of the `Char` values in the `Text` value in a case-insensitive manner.\n\n```haskell\nghci \u003e \"hello world\" `indexOfAnyIgnoreCaseChar` ['E', 'o']\nJust 1\n```\n\n### indexOfChar :: Text -\u003e Char -\u003e Maybe Int\nFind the first occurrence of the `Char` value in the `Text` value.\n\n```haskell\nghci \u003e \"hello WORLD\" `indexOfChar` 'O'\nJust 7\n```\n\n### indexOfIgnoreCaseChar :: Text -\u003e Char -\u003e Maybe Int\nFind the first occurrence of the `Char` value in the `Text` value in a case-insensitive manner.\n\n```haskell\nghci \u003e \"hello WORLD\" `indexOfIgnoreCaseChar` 'O'\nJust 4\n```\n\n### indexOfText :: Text -\u003e Text -\u003e Maybe Int\nFind the first occurrence of the second argument in the first `Text` value.\n\n```haskell\nghci \u003e \"hello WORLD\" `indexOfText` \"O\"\nJust 7\n```\n\n### indexOfIgnoreCaseText :: Text -\u003e Text -\u003e Maybe Int\nFind the first occurrence of the second argument in the first `Text` value in a case-insensitive manner.\n\n```haskell\nghci \u003e \"hello WORLD\" `indexOfIgnoreCaseText` \"O\"\nJust 4\n```\n\n### lastIndexOfAnyChar :: Text -\u003e [Char] -\u003e Maybe Int\nFind the last occurrence of any of the `Char` values in the `Text` value.\n\n```haskell\nghci \u003e \"hello world\" `lastIndexOfAnyChar` ['E', 'o']\nJust 7\n```\n\n### lastIndexOfAnyIgnoreCaseChar :: Text -\u003e [Char] -\u003e Maybe Int\nFind the last occurrence of any of the `Char` values in the `Text` value in a case-insensitive manner.\n\n```haskell\nghci \u003e \"hello world\" `lastIndexOfAnyIgnoreCaseChar` ['e', 'O']\nJust 7\n```\n\n### lastIndexOfChar :: Text -\u003e Char -\u003e Maybe Int\nFind the last occurrence of the `Char` value in the `Text` value.\n\n```haskell\nghci \u003e \"HELLO world\" `lastIndexOfChar` 'O'\nJust 4\n```\n\n### lastIndexOfIgnoreCaseChar :: Text -\u003e Char -\u003e Maybe Int\nFind the last occurrence of the `Char` value in the `Text` value in a case-insensitive manner.\n\n```haskell\nghci \u003e \"HELLO world\" `lastIndexOfIgnoreCaseChar` 'O'\nJust 7\n```\n\n### lastIndexOfText :: Text -\u003e Text -\u003e Maybe Int\nFind the last occurrence of the second argument in the first `Text` value.\n\n```haskell\nghci \u003e \"hello world\" `lastIndexOfText` \"o\"\nJust 7\n```\n\n### lastIndexOfIgnoreCaseText :: Text -\u003e Text -\u003e Maybe Int\nFind the last occurrence of the second argument in the first `Text` value in a case-insensitive manner.\n\n```haskell\nghci \u003e \"hello WORLD\" `lastIndexOfIgnoreCaseText` \"O\"\nJust 7\n```\n\n# License\nThis package is licensed under Apache 2.0. See `LICENSE` file for complete terms on the license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjorg%2Fsimple","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbjorg%2Fsimple","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjorg%2Fsimple/lists"}