Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Composing with Freyas and not Freyas #182

Closed
Vidarls opened this issue Mar 1, 2016 · 2 comments
Closed

Composing with Freyas and not Freyas #182

Vidarls opened this issue Mar 1, 2016 · 2 comments

Comments

@Vidarls
Copy link
Contributor

Vidarls commented Mar 1, 2016

I think I'm doing it wrong, but I currently find that going back and forth between what is inside a Freya computation and what is outside is causing me a lot of pain.

How do I best compose a function within a freya with an argument from outside the freya:

let myFreyaFunc = 
    Freya.init(fun (arg1:string) (arg2:string) -> arg1 + ", " + arg2)

with a normal Non-Freya func I can do:

let myNonFreyaFunc arg1 arg2 =  arg1 + ", " + arg2
//Currently: string->string->string

let composed = myNonFreyaFunc "string1"
//Now becomes string->string

How do I achieve the same in Freya without a lot of ceremony?

The opposite is easy using Freya.map (or operator)

let myFreyaValue = Freya.init("test")

let myNonFreyaFunc value = value + "more"

let result = myNonFreyaFunc <!> myFreyaValue
//or
let result = Freya.map myNonFreyaFunc myFreyaValue
@kolektiv
Copy link
Member

kolektiv commented Mar 1, 2016

I'm not totally sure I see how you mean. It seems like if you have external args, just leaving them external is fine - then your string -> string -> Freya<string> would partially apply and be string -> Freya<string>. If your arguments themselves are Freya functions, you probably want to look at some of the other composition functions (and perhaps operators). https://github.com/freya-fs/freya/blob/master/src/Freya.Core/Operators.fs#L27-L52 is what's available out of the box - >>= and >=> are often quite useful, but as soon as you get in to composing Freya functions, simple partial application is less useful (or possible!).

@Vidarls
Copy link
Contributor Author

Vidarls commented Mar 3, 2016

Figured this out be rethinking my components a bit. Will do another issue if required. Thanx for getting back to me 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants