This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
Idiom #5 Create a 2D Point data structure
Declare a container type for two floating-point numbers x and y

- Ada
- C
- Caml
- Clojure
- Clojure
- C++
- C#
- C#
- C#
- D
- D
- Dart
- Dart
- Elixir
- Elixir
- Erlang
- Erlang
- Erlang
- Fortran
- Fortran
- Go
- Groovy
- Haskell
- Haskell
- JS
- JS
- Java
- Java
- Java
- Java
- Kotlin
- Lisp
- Lua
- Obj-C
- PHP
- Pascal
- Perl
- Perl
- Python
- Python
- Python
- Python
- Python
- Ruby
- Rust
- Rust
- Scala
- Scheme
- Smalltalk
- VB
-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).
Point = points:new(X, Y),
X = points:x(Point),
Y = points:y(Point).
programming-idioms.org