Permalink
Browse files

(re) Remove .cata from adt, adds to each old structure

This eases transitioning from older structures to newer ones. The new `.cata` didn't have the same semantics as the old one, which was bound to cause hard-to-discover issues
  • Loading branch information...
robotlolita committed Jan 22, 2017
1 parent 19910b4 commit d5e780f4f4264713d476a74fa4d5c248a266b4d5
Showing with 40 additions and 28 deletions.
  1. +0 −28 src/core/adt/data.js
  2. +28 −0 src/data/maybe/maybe.js
  3. +12 −0 src/data/validation/validation.js
View
@@ -117,34 +117,6 @@ function defineVariants(typeId, patterns, adt) {
instead to check if a value belongs to the ADT variant.`);
return true;
},
/*~
* Selects an operation based on this Variant's tag.
*
* The `cata`morphism operation allows a very limited form of
* pattern matching, by selecting an operation depending on this
* value's tag.
*
* ---
* category : Transforming
* type: |
* ('a is Variant).({ 'b: (Object Any) => 'c }) => 'c
* where 'b = 'a[`@@folktale:adt:tag]
*
* deprecated:
* version: 2.0.0
* replacedBy: .matchWith(pattern)
* reason: |
* `.cata()` is not a very intuitive name, and most people are
* not familiar with the term `catamorphism` either. `.matchWith()`
* is more familiar and conveys more information to more people.
*
* ~belongsTo: constructor
*/
cata(pattern) {
warnDeprecation('`.cata(pattern)` is deprecated. Use `.matchWith(pattern)` instead.');
return this.matchWith(pattern);
},
/*~
* Selects an operation based on this Variant's tag.
View
@@ -188,6 +188,34 @@ adtMethods(Maybe, {
assertFunction('Maybe.Nothing#orElse', handler);
return this;
}
},
/*~
* ---
* category: Pattern matching
* signature: cata(pattern)
* type: |
* forall a, b:
* (Maybe a).({
* Nothing: () => b,
* Just: (a) => b
* }) => b
*/
cata: {
/*~
*/
Nothing(pattern) {
warnDeprecation('`.cata(pattern)` is deprecated. Use `.matchWith(pattern)` instead.');
return pattern.Nothing();
},
/*~
*/
Just(pattern) {
warnDeprecation('`.cata(pattern)` is deprecated. Use `.matchWith(pattern)` instead.');
return pattern.Just(this.value);
}
}
});
@@ -165,6 +165,18 @@ adtMethods(Validation, {
assertFunction('Validation.Failure#failureMap', transformation);
return this;
}
},
cata: {
Failure(pattern) {
warnDeprecation('`.cata(pattern)` is deprecated. Use `.matchWith(pattern)` instead.');
return pattern.Failure(this.value);
},
Success(pattern) {
warnDeprecation('`.cata(pattern)` is deprecated. Use `.matchWith(pattern)` instead.');
return pattern.Success(this.value);
}
}
});

0 comments on commit d5e780f

Please sign in to comment.