The pipe operator is awesome because you can use it to “extend” objects without messing with their prototypes.
Missing String.titleCase ? Write your own!
“hello world” |> titleCaseMissing String.titleCase ? Write your own!
“hello world” |> titleCasePersonally, I don't use classes much, but sometimes I think free functions are a little too hard to find, so I tend to experiment with the following pattern.
interface User { … }
const User = {
rename(user: User, newName: string): User { … },
getDisplayName(user: User): string { … }
}
const renke: User = { … }
console.log(User.getDisplayName(renke));
Which makes finding an operation for a certain type easier to find (just write User and trigger autocomplete).The alternative is of course having renameUser (or userRename) and getUserDisplayName (or userGetDisplayname). The prefixed version would make autocomplete easier also.
“hello world” |> titleCase (%)
I'm starting to like the F# proposal more now.
const weather = `https://api.weather.gov/gridpoints/TOP/31,80/forecast`
|> await fetch(%)
|> await %.json()
|> %.properties.periods[0]
In F# it would be much more verbose, const weather = `https://api.weather.gov/gridpoints/TOP/31,80/forecast`
|> fetch
|> await
|> json
|> await
|> x => x.properties.periods[0]
// or |> { properties : { periods: [result] } } => result
Hack will also requires less key strikes for calling functions that have multiple augments.