finos/morphir-elm/8.0.0

NOTE: the latest version is 22.0.2

Formerly Morgan-Stanley/morphir-elm. Search finds this package by either name.

Morphir.IR.Path

Path is a list of names that represents a path in the tree. It's used at various places in the IR to identify types and values.

type alias Path =
List Name

Type that represents a path as a list of names.

fromList : List Name -> Path

Converts a list of names to a path.

toList : Path -> List Name

Converts a path to a list of names.

String conversion

fromString : String -> Path

Translates a string into a path by splitting it into names along special characters. The algorithm will treat any non-word charaters that are not spaces as a path separator.

fromString "fooBar.Baz"
--> Path.fromList
-->     [ Name.fromList [ "foo", "bar" ]
-->     , Name.fromList [ "baz" ]
-->     ]


fromString "foo bar/baz"
--> Path.fromList
-->     [ Name.fromList [ "foo", "bar" ]
-->     , Name.fromList [ "baz" ]
-->     ]
toString : (Name -> String) -> String -> Path -> String

Turn a path into a string using the specified naming convention and separator.

path =
    Path.fromList
        [ Name.fromList [ "foo", "bar" ]
        , Name.fromList [ "baz" ]
        ]


toString Name.toTitleCase "." path
--> "FooBar.Baz"


toString Name.toSnakeCase "/" path
--> "foo_bar/baz"

Utilities

isPrefixOf : Path -> Path -> Bool

Checks if a path is a prefix of another.

isPrefixOf [ [ "foo" ], [ "bar" ] ] [ [ "foo" ] ] == True


isPrefixOf [ [ "foo" ] ] [ [ "foo" ], [ "bar" ] ] == False


isPrefixOf [ [ "foo" ], [ "bar" ] ] [ [ "foo" ], [ "bar" ] ] == True