MyNixOS website logo
Description

Countable Text Inflections.

Provides methods for singularizing and pluralizing text. The library is based on Rails' inflections.

Countable Inflections

License MIT Hackage Stackage LTS Build Status

This library implements pluralization and singularization in a similar way to the rails inflectors

It uses regexes to define the non-standard transformations and therefore doesn't provide much safety. If you need to provide the same pluralization and singularization which rails does out of the box, this will work the same. If you want more you should be using inflections-hs which uses megaparsec to give you more guarantees

Usage

λ: pluralize "person"
"people"

λ: singularize "branches"
"branch"

These can also be given custom inflection matchers

λ: :t singularizeWith
[Inflection] -> Text -> Text

There are 3 different types of transformations:

Match

Takes a PCRE regex and a replacement string.

λ: :t makeMatchMapping
[(RegexPattern, RegexReplace)] -> [Inflection]

λ: let mapping = makeMatchMapping [("(octop)us", "\\1i")]
λ: pluralizeWith mapping "octopus"
"octopi"

Irregular

From singular to plural with no greater pattern.

λ: :t makeIrregularMapping
[(Singular, Plural)] -> [Inflection]

λ: let mapping = makeIrregularMapping [("zombie","zombies")]
λ: pluralizeWith mapping "zombie"
"zombies"

Uncountable

Doesn't have a mapping, word stays the same) so it has the type:

[Text] -> [Inflection]

Inflect

In general you can input a number and singularize or pluralize based on the count, for example:

setReport = do
  sets <- getSets
  n <- length sets
  print $ show n ++ " " ++ inflect "sets" n

This way it'll list as "1 set" or "5 sets" based on the input.

License

MIT - see the LICENSE file.

Metadata

Version

0.3.0

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows