!lheuhImcToQZYTQTuI:nixos.org

Nix on macOS

991 Members
“There are still many issues with the Darwin platform but most of it is quite usable.” — http://yves.gnu-darwin.org158 Servers

Load older messages


SenderMessageTime
12 Dec 2024
@calops:tocards.netcalopsoh wait no that doesn't work13:50:38
@reckenrode:matrix.orgRandy Eckenrode

I don’t know if it’s the best way, but this works:

13:55:35
@reckenrode:matrix.orgRandy Eckenrode *

I don’t know if it’s the best way, but this works:

lib.listToAttrs (lib.imap0 (x: y: lib.nameValuePair (toString x) y) x)
13:55:47
@reckenrode:matrix.orgRandy Eckenrode *

I don’t know if it’s the best way, but this works:

list: lib.listToAttrs (lib.imap0 (x: y: lib.nameValuePair (toString x) list) x)
13:56:44
@reckenrode:matrix.orgRandy Eckenrode *

I don’t know if it’s the best way, but this works:

list: lib.listToAttrs (lib.imap0 (x: y: lib.nameValuePair (toString x) y) list)
13:56:56
@reckenrode:matrix.orgRandy EckenrodeWish Nix supported function composition ….13:57:41
@calops:tocards.netcalopsoh, imap0 is what i was missing, thanks14:05:45
@calops:tocards.netcalopswhat do you mean by function composition ?14:16:22
@winter:catgirl.cloudWinter
In reply to @reckenrode:matrix.org
Wish Nix supported function composition ….
be the change you wanna see in the world :3
14:33:05
@reckenrode:matrix.orgRandy Eckenrode
In reply to @calops:tocards.net
what do you mean by function composition ?

In F#, I could write that as something like:

lib.map0 (toString >> lib.nameValuePair) >> lib.listToAttrs
14:44:30
@reckenrode:matrix.orgRandy Eckenrode >> is equivalent to . in Haskell. 14:44:51
@reckenrode:matrix.orgRandy Eckenrode * >> is equivalent to . in Haskell. 14:44:58
@reckenrode:matrix.orgRandy EckenrodeFunction composition takes two functions. After the first is evaluated, the second is evaluated with the result of the first.14:46:11
@reckenrode:matrix.orgRandy Eckenrode(f ∘ g) x = f (g x)14:47:57
@reckenrode:matrix.orgRandy Eckenrode *

>> is equivalent to . in Haskell.

Actually, << is equivalent. F# supports both left and right composition. I prefer >> because it reads like constructing a pipeline.

14:48:56
@reckenrode:matrix.orgRandy Eckenrode
In reply to @winter:catgirl.cloud
be the change you wanna see in the world :3
They haven’t even accepted the piping operator yet, and composition has potentially way worse impacts on readability.
14:50:01
@reckenrode:matrix.orgRandy EckenrodeAlso, I have no bandwidth for stuff like that. 😮14:50:19
@reckenrode:matrix.orgRandy Eckenrode * 14:50:34
@winter:catgirl.cloudWinter
In reply to @reckenrode:matrix.org
They haven’t even accepted the piping operator yet, and composition has potentially way worse impacts on readability.
Lix has ;) (I think)
14:50:48
@reckenrode:matrix.orgRandy Eckenrode (The piping operator is |>. It didn’t come from F#, but it was popularized by it AFAIK.) 14:52:45
@reckenrode:matrix.orgRandy EckenrodeI actually don’t use it much. It reads kind of fugly. I prefer composition or plain function calls usually. It can be really helpful for type inference though.14:53:55
@bryan.bennett:matrix.orgBryan

Maybe helpful additional information: |> (or "pipe last") is a standardML-ism, as far as i can tell.
WRT composition: |> is function composition, but the functions are curried.

In StandardML (as in Nix and F#), functions are unary so you write a lot of let add = x: y: x + y. This means you can partially apply add trivially with let add2 = add 2. |> is simply an infix operator that translates add2 4 to 4 |> add2. For such a trivial example, it's really neither required nor helpful.

This operator really shines when you have something that does repeated list/vector/array processing pipelines: let eleven = [1, 2, 3,4 ] |> List.filter i: i %2 == 0 |> List.map i: i*i | List.fold 0 i: i + i; (or something). IMO it really well encompasses the idea of "we have a bunch of steps and we're doing them in succession to find a final result".

but there are a lot of useless uses of it in the wild too. To each their own tho.

17:59:03
@toonn:matrix.orgtoonn They're both technically function composition but the common interpretation of composition is the mathematical one Randy gave. "Pipe" just has the argument order flipped. 18:28:18
@bryan.bennett:matrix.orgBryan Oh absoluitely. I'm not indicating otherwise. Just clarifying :)18:37:19
@adam:robins.wtfadamcstephens I think pipes are rendering not as useful due to the order of arguments for most nixpkgs lib functions  19:45:33
@adam:robins.wtfadamcstephens * I think pipes are rendered not as useful due to the order of arguments for most nixpkgs lib functions  19:45:42
@szlend:matrix.orgszlend Iirc the proposal is consistent with how most of nixpkgs.lib works 19:52:10
@szlend:matrix.orgszlendso the argument is piped last, vs for example in elixir where it's first19:52:58
@szlend:matrix.orgszlendMost of the nixpkgs lib is design with currying in mind, so that works pretty naturally. Though there are some exceptions to this rule19:56:03
@szlend:matrix.orgszlend removeAttrs comes to mind, but that's a Nix mistake 19:57:10

There are no newer messages yet.


Back to Room ListRoom Version: 6