Just another stackoverflow account
The account with the account ID before me https://magento.stackexchange.com/users/104655/spyros-popos
copied the URL of this post the second it was posted on 21st of April 2020 at 12:18
https://stackoverflow.com/questions/61340835/jstl-core-formatnumber-type-percent/61341107#61341107
This is my best friend: https://stackoverflow.com/users/9925119/rugbr%c3%b8d
type User = { name: string, gender: 'male' | 'female' }
// Vote for gender equality!
type GenderFluidUser = {
[K in keyof User]: User[K] extends 'male' | 'female' ? any : User[K]
}
#Love playing with types
Always keep your Promise
let x = Promise.resolve(5)
let y = Promise.resolve(0)
let safe_divisision = (x: Promise<number>) => (y: Promise<number>): Promise<number> => x.then(valueX =>
y.then(valueY => {
if (valueY == 0) {
return Promise.reject(`Cannot divide by 0 : ${valueX}/${valueY}`)
}
return Promise.resolve(valueX/valueY)
})
)
safe_divisision(x)(y).then(result => alert(result)).catch(reason => alert(reason))
userID: 11.534.547 Wish this was the amount of money on my bank account
Users next to me:
- https://stackoverflow.com/users/11534548/
- https://stackoverflow.com/users/11534549/
- https://stackoverflow.com/users/11534550/
- https://stackoverflow.com/users/11534551/
- https://stackoverflow.com/users/11534552/
FUNCTIONAL PROGRAMMING FOR LIFE!!!!!!!!!!!
type Fun<a, b> = (_: a) => b
type Option<T> = {
kind: 'some'
v: T
} | {
kind: 'none'
}
let Some = <a>(v: a): Option<a> => ({ kind: 'some', v: v })
let None = <a>(): Option<a> => ({kind: 'none'})
let map_Option = <a, b>(f: Fun<a, b>, option: Option<a>): Option<b> =>
option.kind == 'some' ? Some(f(option.v)) : None()
let join_option = <a>(option_of_option: Option<Option<a>>): Option<a> =>
option_of_option.kind == 'some' ? option_of_option.v : option_of_option
let bind_Option = <a, b>(option: Option<a>, q: Fun<a, Option<b>>): Option<b> =>
join_option(map_Option(q, option))
let a = Some(5)
let b = Some(2)
let divide_options = (x: Option<number>) => (y: Option<number>): Option<number> => bind_Option(x, valueX =>
bind_Option(y, valueY => {
if (valueY == 0) {
return None()
}
return Some(valueX/valueY)
})
)
alert(divide_options(a)(b).kind)
CODE
program script that present more then print "Hello World"