Open
Description
Several elm-geometry
constructors use a similar naming pattern using with
as part of the name, e.g.:
Circle2d.withRadius : Quantity Float units -> Point2d units coordinates -> Circle2d units coordinates
Axis3d.withDirection : Direction3d coordinates -> Point3d units coordinates -> Axis3d units coordinates
Vector2d.withLength : Quantity Float units -> Direction2d coordinates -> Vector2d units coordinates
These are reasonably concise (e.g. compare Vector2d.withLength
to Vector2d.fromLengthAndDirection
) and work well with partial application; for example, you can create a bunch of circles with the same radius at different points using
List.map (Circle2d.withRadius (Length.centimeters 5)) listOfPoints
However, there are some downsides:
- As pointed out by @MartinSStewart, the names can sound more like 'modifiers' than 'constructors', e.g.
Vector2d.withLength
sounds like it might take an existingVector2d
and adjust it to have the given length - The
with
keyword has specific meanings in other programming languages, such as referring to resource handling/cleanup in Python, which may be confusing
For the next major release of elm-geometry
, it may be worth reconsidering this pattern and seeing if there's an alternative that is more clear.