Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Erlang
PointAsATuple = {X, Y}.
-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.

to use this module from somewhere else you do stuff like...
Point = points:new(X, Y),
X = points:x(Point),
Y = points:y(Point).
PointAsAMap = #{x => X, y => Y}.
type Point is
   record
      X : Float;
      Y : Float;
   end record;

New implementation...
< >
programming-idioms.org