finos / morphir-elm / 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 Morphir.IR.Name.Name

Type that represents a path as a list of names.

fromList : List Morphir.IR.Name.Name -> Path

Converts a list of names to a path.

toList : Path -> List Morphir.IR.Name.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 : (Morphir.IR.Name.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 -> Basics.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