objcio / functional-swift

Issue repository for the Functional Swift book
http://www.objc.io/books/fpinswift
927 stars 133 forks source link

Applicative Functor #101

Closed onmyway133 closed 8 years ago

onmyway133 commented 9 years ago

I'm reading chapter Functor, Applicative Functor and Monads, section Applicative Functor

There is an example about Region

> Applicative functors have been lurking in the background throughout this book. For example, the Region struct defined above is also an applicative functor:

func pure<A>(value: A) -> Region<A> {
    return Region { pos in value }
}

func <*><A,B>(regionF: Region<A -> B>, 
              regionX: Region<A>) -> Region<B> {

    return Region { pos in regionF.value(pos)(regionX.value(pos)) }
}

Can you explain more about this Region { pos in regionF.value(pos)(regionX.value(pos)) } ? What is the value inside regionF? Can you give an example?

floriankugler commented 9 years ago

@onmyway133 Look a few paragraphs above. There the struct Region<T> is introduced which has the value property.