-
Notifications
You must be signed in to change notification settings - Fork 0
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
silohero
committed
Dec 18, 2023
0 parents
commit 9de9fc3
Showing
9 changed files
with
217 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
on: [push, pull_request] | ||
name: CI | ||
jobs: | ||
build: | ||
name: "Build on Racket '${{ matrix.racket-version }}' (${{ matrix.racket-variant }})" | ||
runs-on: ubuntu-latest | ||
continue-on-error: ${{ matrix.experimental || false }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
racket-version: ["stable", "current"] | ||
racket-variant: ["BC", "CS"] | ||
include: | ||
- racket-version: current | ||
experimental: true | ||
steps: | ||
- uses: actions/checkout@v3.1.0 | ||
- uses: Bogdanp/setup-racket@v1.9.1 | ||
with: | ||
architecture: x64 | ||
distribution: full | ||
variant: ${{ matrix.racket-variant }} | ||
version: ${{ matrix.racket-version }} | ||
- name: Installing monadicrkt and its dependencies | ||
run: raco pkg install --no-docs --auto --name monadicrkt | ||
- name: Compiling monadicrkt and building its docs | ||
run: raco setup --check-pkg-deps --unused-pkg-deps monadicrkt | ||
- name: Testing monadicrkt | ||
run: raco test -x -p monadicrkt |
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,6 @@ | ||
*~ | ||
\#* | ||
.\#* | ||
.DS_Store | ||
compiled/ | ||
/doc/ |
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,23 @@ | ||
monadicrkt | ||
|
||
MIT License | ||
|
||
Copyright (c) 2023 hdbian | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,14 @@ | ||
monadicrkt | ||
========== | ||
|
||
monadic containers for Racket | ||
|
||
|
||
## Usage | ||
|
||
```racket | ||
(require monadicrkt) | ||
(define foo (make-nothing)) | ||
``` |
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,9 @@ | ||
#lang info | ||
(define collection "monadicrkt") | ||
(define deps '("base")) | ||
(define build-deps '("scribble-lib" "racket-doc" "rackunit-lib")) | ||
(define scribblings '(("scribblings/monadicrkt.scrbl" ()))) | ||
(define pkg-desc "Description Here") | ||
(define version "0.0") | ||
(define pkg-authors '(dbian)) | ||
(define license '(MIT)) |
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,55 @@ | ||
#lang racket/base | ||
|
||
(require "src/result.rkt") | ||
(require "src/maybe.rkt") | ||
|
||
(provide (all-from-out "src/result.rkt" "src/maybe.rkt")) | ||
|
||
(module+ test | ||
(require rackunit)) | ||
|
||
;; Notice | ||
;; To install (from within the package directory): | ||
;; $ raco pkg install | ||
;; To install (once uploaded to pkgs.racket-lang.org): | ||
;; $ raco pkg install <<name>> | ||
;; To uninstall: | ||
;; $ raco pkg remove <<name>> | ||
;; To view documentation: | ||
;; $ raco docs <<name>> | ||
;; | ||
;; For your convenience, we have included LICENSE-MIT and LICENSE-APACHE files. | ||
;; If you would prefer to use a different license, replace those files with the | ||
;; desired license. | ||
;; | ||
;; Some users like to add a `private/` directory, place auxiliary files there, | ||
;; and require them in `main.rkt`. | ||
;; | ||
;; See the current version of the racket style guide here: | ||
;; http://docs.racket-lang.org/style/index.html | ||
|
||
;; Code here | ||
|
||
|
||
|
||
(module+ test | ||
;; Any code in this `test` submodule runs when this file is run using DrRacket | ||
;; or with `raco test`. The code here does not run when this file is | ||
;; required by another module. | ||
|
||
(check-equal? (+ 2 2) 4)) | ||
|
||
(module+ main | ||
;; (Optional) main submodule. Put code here if you need it to be executed when | ||
;; this file is run using DrRacket or the `racket` executable. The code here | ||
;; does not run when this file is required by another module. Documentation: | ||
;; http://docs.racket-lang.org/guide/Module_Syntax.html#%28part._main-and-test%29 | ||
|
||
(require racket/cmdline) | ||
(define who (box "world")) | ||
(command-line | ||
#:program "my-program" | ||
#:once-each | ||
[("-n" "--name") name "Who to say hello to" (set-box! who name)] | ||
#:args () | ||
(printf "hello ~a~n" (unbox who)))) |
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,10 @@ | ||
#lang scribble/manual | ||
@require[@for-label[monadicrkt | ||
racket/base]] | ||
|
||
@title{monadicrkt} | ||
@author{hdbian} | ||
|
||
@defmodule[monadicrkt] | ||
|
||
Package Description Here |
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,30 @@ | ||
#lang racket | ||
(provide (all-defined-out)) | ||
|
||
(struct maybe-type-just [value]) | ||
(struct maybe-type-nothing []) | ||
|
||
(define (make-just value) | ||
(maybe-type-just value)) | ||
|
||
(define (make-nothing) | ||
(maybe-type-nothing)) | ||
|
||
(define (maybe-type? x) | ||
(or (maybe-type-just? x) | ||
(maybe-type-nothing? x))) | ||
|
||
(define (maybe-map maybe f) | ||
(cond ((maybe-type-just? maybe) | ||
(make-just (f (maybe-type-just-value maybe)))) | ||
((maybe-type-nothing? maybe) | ||
maybe))) | ||
|
||
(define (maybe-bind maybe f) | ||
(cond ((maybe-type-just? maybe) | ||
(f (maybe-type-just-value maybe))) | ||
((maybe-type-nothing? maybe) | ||
maybe))) | ||
|
||
(define (maybe-just-value maybe) | ||
(maybe-type-just-value maybe)) |
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,41 @@ | ||
|
||
#lang racket | ||
(require "maybe.rkt") | ||
(struct result-type-success [value]) | ||
(struct result-type-error [message]) | ||
|
||
(define (make-success value) | ||
(result-type-success value)) | ||
|
||
(define (make-error message) | ||
(result-type-error message)) | ||
|
||
(define (result-type? x) | ||
(or (result-type-success? x) | ||
(result-type-error? x))) | ||
|
||
(define (result-map result f) | ||
(cond ((result-type-success? result) | ||
(make-success (f (result-type-success-value result)))) | ||
((result-type-error? result) | ||
result))) | ||
|
||
(define (result-bind result f) | ||
(cond ((result-type-success? result) | ||
(f (result-type-success-value result))) | ||
((result-type-error? result) | ||
result))) | ||
|
||
(define (result2maybe result) | ||
(cond ((result-type-success? result) | ||
(make-just (result-type-success-value result))) | ||
((result-type-error? result) | ||
(make-nothing)))) | ||
|
||
(define (result-success-val result) | ||
(result-type-success-value result)) | ||
|
||
(define (result-error-val result) | ||
(result-type-error-message result)) | ||
|
||
(provide (all-defined-out)) |