Releases: alex-lairan/monads
v1.2.2
What's Changed
New Features
- Maybe
value_orblock support: You can now usevalue_or { default }with Maybe monads
# Just returns its value
Monads::Just.new(42).value_or { 0 } # => 42
# Nothing calls the block
Monads::Nothing(Int32).new.value_or { 0 } # => 0Full Changelog: v1.2.1...v1.2.2
v1.2.1
What's Changed
Improvements
- Updated CI: Now testing against Crystal 1.15, 1.16, 1.17, 1.18, 1.19 + nightly
- Updated ameba to 1.6.0 for better linting
Bug Fixes
- Fixed typo
ohter→otherin Maybe monad - Fixed unused argument warning in Either fold
- Fixed
not_nil!usage in Try monad - Fixed operator parameter naming (
rhs→other)
Documentation
- Added
foldmethod examples to README
Full Changelog: v1.2.0...v1.2.1
v1.2.0
What's New
New Features
- fold method for Either: Pattern match on
Right/Left/LeftExceptionwith two functions - fold method for Maybe: Pattern match on
Just/Nothingwith two functions - Block version of fold that raises on error cases
Bug Fixes
- Fixed parameter name warnings across
Either,Maybe, andListmodules
Example Usage
# Either fold
result = Monads::Right(String, Int32).new(42).fold(
->(x : Int32) { "success: #{x}" },
->(e : String) { "error: #{e}" }
)
# => "success: 42"
# Maybe fold
value = Monads::Just.new(42).fold(
->(x : Int32) { "value: #{x}" },
->{ "nothing" }
)
# => "value: 42"Full Changelog: v1.1.0...v1.2.0
v1.1.0 - Doubly parameterized Either
What's Changed
Make Either doubly parameterized for proper type unification.
Breaking Changes
Right(T)is nowRight(E, T)inheriting fromEither(E, T)Left(E)is nowLeft(E, T)inheriting fromEither(E, T)LeftExceptionis nowLeftException(T)inheriting fromEither(Exception, T)
Why?
This enables functions to return Either(E, T) where both Right and Left branches can unify to the same type:
def divide(a : Int32, b : Int32) : Either(Exception, Int32)
if b == 0
LeftException(Int32).new(DivisionByZeroError.new)
else
Right(Exception, Int32).new(a // b)
end
endFull Changelog: v1.0.0...v1.1.0
Stable
Stable version compatible with Crystal 1.0
Allow Block alongside Proc
Crystal 0.32.1 Compatibility
v0.6.0 Remove return types removing warnings
Crystal 0.29.0 Compatibility
#53 Make Monads compatible with Crystal 0.29.0
Add Try and Task
New Try monad
=> #47
New Task monad
=> #45
Improve List monad
Initialize list with [](*args)
=> #34
Add List#reverse
=> #41
Add Comparable
=> https://github.com/alex-lairan/monads/pull/35/files
Add List#next and Indexable
=> #36
=> #42
Add #sort and #sort_by
=> #43
=> #44
Add #permutations, #subsequences and #join
=> #40
Add #last and #empty
=> #39
Add #to_s and #inspect
=> #38
Misc
Add #| (bind) and #>> (sequence) operator
=> #46
Update readme
=> #48
=> #50 Thanks @amelie-certin
Functional paradigms naming and behaviors
Implement Comparable(T) to Maybe monad and remove redundant #== method.
Multiples methods reimplementations.
Create Monad(T) and Fonctor(T)
=> #6
=> #16
=> #19
=> #20
=> #23
=> #24
=> #27
=> #28
=> #29
=> #30
=> #31
=> #32
Use structs instead of classes
Rename Result to Either
=> #10
Add #inspect for Maybe monads and Either
Add a CI
Fix Block type introspection by using a proc
=> #25