Principal Curves In Metric Spaces And The Space Of Probability Measures