2019-11-26 06:03:04 +00:00
|
|
|
---
|
|
|
|
layout: pattern
|
|
|
|
title: Combinator
|
|
|
|
folder: combinator
|
|
|
|
permalink: /patterns/combinator/
|
2019-12-13 21:09:28 +02:00
|
|
|
categories: Idiom
|
2021-05-19 10:49:05 -06:00
|
|
|
language: en
|
2019-11-26 06:03:04 +00:00
|
|
|
tags:
|
|
|
|
- Reactive
|
|
|
|
---
|
|
|
|
|
|
|
|
## Also known as
|
|
|
|
Composition pattern
|
|
|
|
|
|
|
|
## Intent
|
|
|
|
The functional pattern representing a style of organizing libraries centered around the idea of combining functions.
|
|
|
|
Putting it simply, there is some type T, some functions for constructing "primitive" values of type T,
|
|
|
|
and some "combinators" which can combine values of type T in various ways to build up more complex values of type T.
|
|
|
|
|
2019-12-07 20:01:13 +02:00
|
|
|
## Class diagram
|
|
|
|

|
2019-11-26 06:03:04 +00:00
|
|
|
|
|
|
|
## Applicability
|
|
|
|
Use the combinator pattern when:
|
2019-12-13 21:09:28 +02:00
|
|
|
|
2019-11-26 06:03:04 +00:00
|
|
|
- You are able to create a more complex value from more plain values but having the same type(a combination of them)
|
|
|
|
|
|
|
|
## Real world examples
|
2019-12-13 21:09:28 +02:00
|
|
|
|
2019-11-26 06:03:04 +00:00
|
|
|
- java.util.function.Function#compose
|
|
|
|
- java.util.function.Function#andThen
|
|
|
|
|
|
|
|
## Credits
|
2019-12-13 21:09:28 +02:00
|
|
|
|
2019-11-26 06:03:04 +00:00
|
|
|
- [Example for java](https://gtrefs.github.io/code/combinator-pattern/)
|
|
|
|
- [Combinator pattern](https://wiki.haskell.org/Combinator_pattern)
|
2019-12-13 21:09:28 +02:00
|
|
|
- [Combinatory logic](https://wiki.haskell.org/Combinatory_logic)
|