Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

xvw/coers

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

coers

Coers is a very small library to provide small coercion on primitive types in Erlang. This library was built essentially for internal tools at derniercri.io

Build & test

$ # Compile the library
$ rebar3 compile
$ # run the tests using eUnit
$ rebar3 eunit

Usage

You can run an erlang shell with coers completely loaded : rebar3 shell :

===> Verifying dependencies...
===> Compiling coers
Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false] [dtrace]

Eshell V8.1  (abort with ^G)

Basics

Each coercion is wrapped into a special record:

-record(result, {
  succeeded :: boolean(),
  value     :: term()
}).

If a coercion fail, the value member is assigned with a default value and the succeed member is false. If the coersion succeed, the value member becomes the coerced data and the succeed member becomes true.

You can use these 3 combinators to have information about coercion status :

  • -spec succeed(result()) -> boolean().
  • -spec fail(result()) -> boolean().
  • -spec value(result()) -> term().

For example :

1> X = coers:to_int("10").
{result,true,10}
2> Y = coers:to_int("foo").
{result,false,0}
3> [coers:succeed(X), coers:succeed(Y), coers:fail(X), coers:fail(Y)].
[true,false,false,true]
4> [coers:value(X), coers:value(Y)].
[10,0]

Documentation

This page exposes the feature list : http://xvw.github.io/coers/coers.html

About

A small library for coercion to primitive Erlang types.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.