-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3d5e58
commit fc75b91
Showing
7 changed files
with
194 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import type { PDataRepresentable } from "../../../PType/PDataRepresentable"; | ||
import type { PBool, PDelayed, PList, TermFn } from "../../../PTypes"; | ||
import { PAlias, palias } from "../../../PTypes/PAlias/palias"; | ||
import { TermType, list, lam, bool, delayed, AliasT, ListT, ToPType } from "../../../type_system"; | ||
import { punsafeConvertType } from "../../punsafeConvertType"; | ||
import { pfn } from "../../pfn"; | ||
import { phoist } from "../../phoist"; | ||
import { perror } from "../../perror"; | ||
import { pforce } from "../../pforce"; | ||
import { pdelay } from "../../pdelay"; | ||
import { pisEmpty } from "../../builtins/list"; | ||
import { pif, pstrictIf } from "../../builtins/bool"; | ||
|
||
export type ListMaybeT<T extends TermType> = | ||
AliasT<ListT<T>,{ | ||
isNothing: TermFn<[ PList<ToPType<T>> ], PBool>, | ||
unwarpOrFail: TermFn<[ PList<ToPType<T>> ], ToPType<T>> | ||
unwarpOrElse: TermFn<[ PList<ToPType<T>>, PDelayed<ToPType<T>> ], ToPType<T>> | ||
}> | ||
|
||
export type PListMaybeT<PTy extends PDataRepresentable> = | ||
PAlias<PList<PTy>,{ | ||
isNothing: TermFn<[ PList<PTy> ], PBool>, | ||
unwarpOrFail: TermFn<[ PList<PTy> ], PTy> | ||
unwarpOrElse: TermFn<[ PList<PTy>, PDelayed<PTy> ], PTy> | ||
}> | ||
|
||
export function PListMaybe<T extends TermType>(tyArg: T): PListMaybeT<ToPType<T>> | ||
{ | ||
return palias( | ||
list( tyArg ), | ||
self_t => { | ||
|
||
return { | ||
isNothing: punsafeConvertType( pisEmpty, lam( self_t, bool ) ), | ||
unwrapOrFail: phoist( | ||
pfn([ self_t ], tyArg) | ||
( self => | ||
pif( tyArg ).$( pisEmpty.$( self ) ) | ||
.then( perror( tyArg ) ) | ||
.else( self.head ) | ||
) | ||
), | ||
unwarpOrElse: phoist( | ||
pfn([ self_t, delayed( tyArg ) ], tyArg) | ||
(( self, weDontLikeThat ) => | ||
pforce( | ||
pstrictIf( delayed( tyArg ) ).$( pisEmpty.$( self ) ) | ||
.$( weDontLikeThat ) | ||
.$( pdelay( self.head ) ) | ||
) | ||
) | ||
) | ||
} | ||
} | ||
) as any; | ||
} |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./PMaybe"; | ||
export * from "./PMaybe"; | ||
export * from "./PListMaybe"; |
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
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,21 @@ | ||
import { bool, str, unit } from "../../type_system/types"; | ||
import { pif } from "../builtins/bool"; | ||
import { ptraceError } from "../builtins/ptrace"; | ||
import { perror } from "../perror"; | ||
import { pfn } from "../pfn"; | ||
import { phoist } from "../phoist"; | ||
import { pmakeUnit } from "./unit/pmakeUnit"; | ||
|
||
export const passert = phoist( | ||
pfn([ bool ], unit) | ||
( condition => pif( unit ).$( condition ).then( pmakeUnit() ).else( perror( unit ) ) ) | ||
); | ||
|
||
export const passertOrTrace = phoist( | ||
pfn([ str, bool ], unit) | ||
( (msg, condition) => | ||
pif( unit ).$( condition ) | ||
.then( pmakeUnit() ) | ||
.else( ptraceError( unit ).$( msg ) ) | ||
) | ||
); |