From 3a341d479d18bb593646516dc7831feead8d8548 Mon Sep 17 00:00:00 2001 From: David Chambers Date: Wed, 3 Jan 2018 23:06:59 +0100 Subject: [PATCH] =?UTF-8?q?add=20derivation=20from=20=E2=80=98concat?= =?UTF-8?q?=E2=80=99,=20=E2=80=98of=E2=80=99,=20=E2=80=98zero=E2=80=99,=20?= =?UTF-8?q?and=20=E2=80=98reduce=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index be37999..4778fad 100644 --- a/README.md +++ b/README.md @@ -886,6 +886,16 @@ to implement certain methods then derive the remaining methods. Derivations: } ``` + - [`filter`][] may be derived from [`concat`][], [`of`][], [`zero`][], and + [`reduce`][]: + + ```js + function(pred) { + var F = this.constructor; + return this.reduce((f, x) => pred(x) ? f.concat(F.of(x)) : f, F.zero()); + } + ``` + If a data type provides a method which *could* be derived, its behaviour must be equivalent to that of the derivation (or derivations).