fuzion icon indicating copy to clipboard operation
fuzion copied to clipboard

hide specific apis?

Open michaellilltokiwa opened this issue 1 month ago • 2 comments

An example:

  # create string from the given utf8 bytes
  #
  public type.from_bytes(utf8_bytes Sequence u8) String =>
    ref : String is
      public redef utf8 Sequence u8 := utf8_bytes.as_array_backed


  # create string from the given codepoints
  #
  public type.from_codepoints(codepoints Sequence codepoint) String =>
    String.from_bytes (codepoints.flat_map (.utf8))


  # create string from the given data
  #
  # where data might either be utf8 bytes or codepoints
  #
  public type.from(data choice (Sequence u8) (Sequence codepoint)) String =>
    match data
      bytes Sequence u8 => String.from_bytes bytes
      codepoints Sequence codepoint => String.from_codepoints codepoints

Here we could set visibility of from_codepoints, from_bytes to private, exposing only from. Upside would be that the API surface is smaller and thus possible easier to grasp. Your opinions on cases like this?

michaellilltokiwa avatar Nov 04 '25 11:11 michaellilltokiwa

I think this would make sense, maybe we could even delete those APIs.

Somewhat related: It might make sense to use | syntax sugar to improve readability here, maybe like this (hope this works, I think it should ...:-)

  public type.from(data Sequence u8
                      | Sequence codepoint
                  ) String
  =>

fridis avatar Nov 04 '25 12:11 fridis

I don't think we should delete the private APIs, this keeps the implementation of the "unified" from feature clean.

maxteufel avatar Nov 04 '25 12:11 maxteufel