List.Range and Svg

Hi @jonohovon! I think you’re absolutely right that the current elm/svg package is a bit awkward to work with, but as discussed in the package description:

This package should only change to account for new SVG tags and attributes.

Just like elm/html , this package is designed to be predictable. Every node takes two arguments (a list of attributes and a list of children) even though in many cases it is possible to do something nicer. So if you want nice helpers for simple shapes (for example) I recommend creating a separate package that builds upon this one.

There are indeed packages that build on elm/svg to provide a nicer, more type-safe interface, the main one probably being elm-community/typed-svg. (There’s also my own ianmackenzie/elm-geometry-svg, and several others if you search the package web site.)

How would this work? For example, what would List.range 0.1 0.5 return? For non-integers you need to specify something like a maximum step size to take between numbers, or the total number of steps to take; I’ve taken the latter approach in my elm-float-extra package, which has a range function with the signature

range : { start : Float, end : Float, steps : Int } -> List Float

For example:

Float.Extra.range { start = 2, end = 3, steps = 5 }
--> [ 2, 2.2, 2.4, 2.6, 2.8, 3 ]
2 Likes