Logo

Programming-Idioms

History of Idiom 5 > diff from v344 to v345

Edit summary for version 345 by :
New Erlang implementation by user [elbrujohalcon]

Version 344

2015-11-01, 23:07:14

Version 345

2015-11-18, 11:58:12

Idiom #5 Create a 2D Point data structure

Declare a container type for two floating-point numbers x and y

Idiom #5 Create a 2D Point data structure

Declare a container type for two floating-point numbers x and y

Code
-module(points).
-export([new/2, x/1, y/1]).

-opaque point() :: #{x => float(), y => float()}.
-export_type([point/0]).

-spec new(float(), float()) -> point().
new(X, Y) -> #{x => X, y => Y}.

-spec x(point()) -> float().
x(#{x := X}) -> X.

-spec y(point()) -> float().
y(#{y := Y}) -> Y.