-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor to use it to boot the app w/o blowing up in the browser. Populate window.initialData in a browser context. One more util fn. :)
- Loading branch information
1 parent
e3e76bd
commit ecf0724
Showing
4 changed files
with
72 additions
and
30 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
export const Right = x => | ||
({ | ||
chain: f => f(x), | ||
map: f => Right(f(x)), | ||
fold: (f, g) => g(x), | ||
inspect: () => `Right(${x})` | ||
}); | ||
|
||
Right.of = function of(x) { | ||
return new Right(x); | ||
}; | ||
|
||
export function right(x) { | ||
return Right.of(x); | ||
} | ||
|
||
export const Left = x => | ||
({ | ||
chain: f => Left(x), | ||
map: f => Left(x), | ||
fold: (f, g) => f(x), | ||
inspect: () => `Left(${x})` | ||
}); | ||
|
||
Left.of = function of(x) { | ||
return new Left(x); | ||
}; | ||
|
||
export function left(x) { | ||
return Left.of(x); | ||
} | ||
|
||
export const fromNullable = x => | ||
( | ||
x !== null && | ||
x !== undefined && | ||
x !== false && | ||
x !== 'undefined' | ||
) | ||
? Right(x) | ||
: Left(null); | ||
|
||
export const tryCatch = f => { | ||
try { | ||
return Right(f()); | ||
} catch (e) { | ||
return Left(e); | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const pretty = x => JSON.stringify(x, null, 2); |