How to create your own arrow data type

What are the steps to creating my own data type when using the arrow.

Just use something like Optionwith provided extension constructors such as Some(data)or None. However, how can I create my own data type that has functional operators such as map()or flatMap()?

+7
source share
3 answers

If I understand your question correctly:

https://arrow-kt.io/docs/patterns/glossary/

, . , , . ( , , (), Monad, () Functor.)

0

Arrow, Type, Functor , , , map, :

  1. . https://arrow-kt.io/docs/patterns/glossary/#higher-kinds

  2. https://arrow-kt.io/docs/patterns/glossary/#using-higher-kinds-with-typeclasses

ListK List std lib. , , Functor ListK, map, lift .., Functor kapt arrow.

kapt    "io.arrow-kt:arrow-meta:$arrow_version"

Arrow Higher Kinds Extensions . , @higherkind @extension , - , kapt. . , Arrow, , .

0

(@pablisco) , . .

, :

A datatype is implemented by a data class,
or a sealed hierarchy of data classes and objects. 
These datatypes are generalised by having one or several generic parameters, 
and to become a type constructor they implement the interface Kind for these generic parameters. 
Datatypes work over themselves,
never directly over the values defined by its generic parameters

:

Typeclasses are interfaces that define a set of extension functions
associated to one type. You may see them referred as "extension interfaces".

The other purpose of these interfaces, like with any other unit of abstraction,
is to have a single shared definition of a common API 
and behavior shared across many types in different libraries and codebases.

, , , common API → flatMap/map/just, costume Implementation.

,

-:

  1. , .
  2. , , , common API's .
  3. , , - Codegen, Arrow Team , .
  4. - : arrow-test kotlin-test, , , .

However, if you are really trying to implement your own data type. You can also create a problem, and one of those accompanying you will be happy to help you :)

-1
source

Source: https://habr.com/ru/post/1693945/


All Articles