/* @flow */
type Props = { foo: string };
const View = ({ foo }: Props) => <div>{ foo }</div>;
// Consumer renders View
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://medium.com/@gcanti/higher-kinded-types-in-typescript-static-and-fantasy-land-d41c361d0dbe | |
import { | |
TypeConstructors, | |
TypeConstructors2, | |
Kind, | |
Kind2, | |
} from "./higherKindedTypes"; | |
export interface Functor<F extends TypeConstructors, A> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const runPromisesInSeries = ps => ps.reduce((p, next) => p.then(next), Promise.resolve()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyComponent extends React.Component { | |
render() { | |
return ( | |
<div> | |
{this.props.children('Cruisin down the street')} | |
</div> | |
); | |
} | |
} |
map | flatMap | fold | |
---|---|---|---|
Some(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getUserFromLocalStorage = keyName => { | |
const str = localStorage.getItem(keyName); | |
try { | |
return Right(Option(JSON.parse(str))); | |
} catch (e) { | |
return Left("Invalid or Corrupted User Data"); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getUserFromLocalStorage = keyName => { | |
const str = localStorage.getItem(keyName); | |
try { | |
return Right(JSON.parse(str)); | |
} catch (e) { | |
return Left("Invalid or Corrupted User Data"); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getUserFromLocalStorage = keyName => { | |
const str = localStorage.getItem(keyName); | |
try { | |
return JSON.parse(str); | |
} catch (e) { | |
return "Invalid or Corrupted User Data"; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const transformCage = () => { /* ... */ }; | |
const handleError = e => "Invalid or Corrupted User Data"; | |
const handleSuccess = data => "Success"; | |
const doSomethingWithUserData = () => | |
getUserFromLocalStorage('nickCage') | |
.map(transformCage) | |
.fold(handleError, handleSuccess); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const transformCage = () => { /* ... */ }; | |
const handleError = e => "failed to parse Cage"; | |
const handleSuccess = data => "Success"; | |
const ifEmpty = () => "Cage does not exist!"; | |
const doSomethingWithUserData = () => | |
getUserFromLocalStorage('nickCage') | |
.fold(handleError, | |
data => | |
data.map(transformCage) |
NewerOlder