Logo

Programming-Idioms

History of Idiom 5 > diff from v368 to v369

Edit summary for version 369 by lab419:
New Elixir implementation by user [lab419]

Version 368

2019-09-26, 13:58:01

Version 369

2019-09-26, 14:02:55

Idiom #5 Create a 2D Point data structure

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

Illustration

Idiom #5 Create a 2D Point data structure

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

Illustration
Code
{x, y}
defmodule Point do
  defstruct x: 0.0, y: 0.0
end
Comments bubble
the tuple does the trick but a type is best implemented by a struct which is a module
N.B. the types of x and y can change