# Mix elements of the two styles, OO and FP

**URL:** <https://discuss.kotlinlang.org/t/mix-elements-of-the-two-styles-oo-and-fp/18614>\
**Category:** Language Design\
**Created:** [July 29, 2020, 2:16am UTC](https://discuss.kotlinlang.org/t/mix-elements-of-the-two-styles-oo-and-fp/18614 "2020-07-29T02:16:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gleysoncordeiro](https://avatars.discourse-cdn.com/v4/letter/g/bcef8e/32.png) [@gleysoncordeiro](https://discuss.kotlinlang.org/u/gleysoncordeiro)\
**Post date:** [July 29, 2020, 2:16am UTC](https://discuss.kotlinlang.org/t/mix-elements-of-the-two-styles-oo-and-fp/18614/1 "2020-07-29T02:16:59Z")

</div>

Hello,

I would like examples of mixing OO and FP paradigms in Kotlin. I found no research sources on the subject with simple examples.

“Is Kotlin an object-oriented language or a functional one?  
Kotlin has both object-oriented and functional constructs. You can use it in both OO and FP styles, or mix elements of the two.”  
Reference: [https://kotlinlang.org/docs/reference/faq.html](https://kotlinlang.org/docs/reference/faq.html)

---

<div class="post-metadata">

**Author:** ![Wasabi375](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wasabi375/32/4741_2.png) [@Wasabi375](https://discuss.kotlinlang.org/u/Wasabi375)\
**Post date:** [July 29, 2020, 1:44pm UTC](https://discuss.kotlinlang.org/t/mix-elements-of-the-two-styles-oo-and-fp/18614/2 "2020-07-29T13:44:01Z")

</div>

I’m not sure what your question is exactly. As the docs state: “Kotlin hash both object-oriented and functional constructs”. The two obvious examples are inheritance and higher order functions. Inheritance is an OO feature and higher order functions (the ability to treat functions like any other variable) is the definition of FP.  
I’m not sure what kind of example you are looking for. It’s not like combining OO and FP gives you a third system of programming. This part of the docs just mean that you can use paradigms of both styles.

---

<div class="post-metadata">

**Author:** ![al3c](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@al3c](https://discuss.kotlinlang.org/u/al3c)\
**Post date:** [July 29, 2020, 2:45pm UTC](https://discuss.kotlinlang.org/t/mix-elements-of-the-two-styles-oo-and-fp/18614/3 "2020-07-29T14:45:27Z")

</div>

A minimal example is probably really silly like an object whose constructor takes a function:  
`class Foo(val f:() -> Unit)`

Per se, that’s not particulatly exciting.

---

<div class="post-metadata">

**Author:** ![christophels](https://avatars.discourse-cdn.com/v4/letter/c/7feea3/32.png) [@christophels](https://discuss.kotlinlang.org/u/christophels)\
**Post date:** [July 30, 2020, 11:54am UTC](https://discuss.kotlinlang.org/t/mix-elements-of-the-two-styles-oo-and-fp/18614/4 "2020-07-30T11:54:10Z")

</div>

A good article on FP and OO difference is [here](https://ceylon-lang.org/blog/authors/gavin-king/page6/) (come from ceylon language blog).  
In short, OO & FP are similar; but big difference is between FP vs pure FP (only pure function), which is same as OO vs “immutable only” OO. In this sense, Kotlin is FP/OO language (like majority) and haskell is (pure FP / immutable OO) as all objects are immutable.
