chore: rearrange optics

This commit is contained in:
Ed Langley
2020-10-31 01:05:20 -07:00
parent 8b39d02344
commit befab03521

View File

@ -1,5 +1,42 @@
(in-package :data-lens.lenses) (in-package :data-lens.lenses)
#+fw.dev
(progn
;; maybe functor implementation
(defclass maybe ()
())
(defclass just (maybe)
((%v :initarg :value :reader value)))
(defclass nothing (maybe)
())
(defun just (value)
(make-instance 'just :value value))
(defun nothing (&optional value)
(declare (ignore value))
(make-instance 'nothing))
(defgeneric maybe (default value)
(:method (default (value just))
(value value))
(:method (default (value nothing))
default))
(defgeneric maybe-apply (function value)
(:method (function (value just))
(just (funcall function (value value))))
(:method (function (value nothing))
value))
(defmethod print-object ((o just) s)
(format s "#.(~s ~s)"
'just
(value o)))
(defmethod print-object ((o nothing) s)
(format s "#.(~s)"
'nothing)))
;; identity functor, necessary for set and over ;; identity functor, necessary for set and over
(defclass identity- () (defclass identity- ()
((%v :initarg :value :reader unidentity))) ((%v :initarg :value :reader unidentity)))
@ -180,40 +217,3 @@ contain the new value at the location focused by the lens."
(set 'a-lens 2 (set 'a-lens 2
(make-instance 'foo :a 1)))) #| (make-instance 'foo :a 1)))) #|
==> 3 |#) ==> 3 |#)
#+fw.dev
(progn
;; maybe functor implementation
(defclass maybe ()
())
(defclass just (maybe)
((%v :initarg :value :reader value)))
(defclass nothing (maybe)
())
(defun just (value)
(make-instance 'just :value value))
(defun nothing (&optional value)
(declare (ignore value))
(make-instance 'nothing))
(defgeneric maybe (default value)
(:method (default (value just))
(value value))
(:method (default (value nothing))
default))
(defgeneric maybe-apply (function value)
(:method (function (value just))
(just (funcall function (value value))))
(:method (function (value nothing))
value))
(defmethod print-object ((o just) s)
(format s "#.(~s ~s)"
'just
(value o)))
(defmethod print-object ((o nothing) s)
(format s "#.(~s)"
'nothing)))